1
I am maintaining a code of another programmer and I am facing difficulties in two select.
I need to take the time of each field and add up this interval, so far I’ve done some tests using the lib Moment.js and it fits me perfectly. What I’m getting headaches is in taking the Select values.
In the code there is mixing of pure HTML with a page render framework, TWIG. I’ve tried several ways to read the name, and always returns me Undefined.
Follow the code fragment.
<fieldset class="datas">
<legend class="text-center bg-default border-control">Datas</legend>
<div id="container-data" class="col-xs-10 col-sm-10 col-xs-offset-1 col-sm-offset-1">
<div class="form-group linha-data-template hidden">
<div class="col-sm-1">
<label class="control-label" for="inputDataTemplate">Data</label>
</div>
<div class="col-sm-3">
<div class="input-group">
<input name="inputDataTemplate" id="inputDataTemplate" type="text" class="inputDataTemplate form-control input-sm" placeholder="99/99/9999" maxlength="10" pattern="[0-3][0-9]/[0-1][0-9]/[2][0][1][1-9]" />
<span class="input-group-addon input-sm btn-calendar" style="cursor:pointer;">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="col-sm-1 ">
<label class="control-label" for="cbHorarioIni">Horário</label>
</div>
<div class="col-sm-2">
{{ form_dropdown('cbHorarioIniTemplate', horarios, agendai.A106_Codigo, 'id="cbHorarioIniTemplate" class="input-sm form-control"') }}
</div>
<div class="col-sm-1 text-center">
<label class="control-label" for="cbHorarioFim">às</label>
</div>
<div class="col-sm-2">
{{ form_dropdown('cbHorarioFimTemplate', horarios, agendai.A106_Codigo, 'id="cbHorarioFimTemplate" class="input-sm form-control cbHorarioFimTemplate"') }}
</div>
<div class="col-sm-2">
<a id="removeData" style="cursor: pointer;"><h5><span class="glyphicon glyphicon-remove red"></span></h5></a>
</div>
</div>
{% for nro in 1..agendai.nro_datas %}
<div class="form-group linha-data">
<div class="col-sm-1">
<label class="control-label" for="inputData">Data</label>
</div>
<div class="col-sm-3">
<div class="input-group">
<input name="inputData[]" type="text" class="form-control data input-sm data-esconder" placeholder="99/99/9999" required maxlength="10" pattern="[0-3][0-9]/[0-1][0-9]/[2][0][1][1-9]" value="{{set_value('inputData',agendai.datas[loop.index0].inputData)}}" />
<span class="input-group-addon input-sm btn-calendar" style="cursor:pointer;">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="col-sm-1">
<label class="control-label" for="cbHorarioIni">Horário</label>
</div>
<div class="col-sm-2">
{{ form_dropdown('cbHorarioIni[]', horarios, set_value('cbHorarioIni', agendai.datas[loop.index0].cbHorarioIni), 'class="input-sm form-control selectpicker"') }}
</div>
<div class="col-sm-1 text-center">
<label class="control-label" for="cbHorarioFim">às</label>
</div>
<div class="col-sm-2">
{{ form_dropdown('cbHorarioFim[]', horarios, set_value('cbHorarioFim', agendai.datas[loop.index0].cbHorarioFim), 'class="input-sm form-control selectpicker"') }}
</div>
<div class="col-sm-2 green">
{% if loop.index == 1%}
<a id="addData" style="cursor: pointer;"><h5 class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-plus green "></span> Adicionar Data</h5></a>
{% else %}
<a id="removeData" style="cursor: pointer;"><h5 ><span class="glyphicon glyphicon-remove red "></span></h5></a>
{% endif %}
</div>
</div>
{% endfor %}
</div>
</fieldset>
How is code you use to get the value of select?
– rray
This is the Pastebin link.
– Luis Renato H. Jr.
But I don’t know what code js you use.
– rray
Ok... This is the code I’m trying to use to capture the value of select. https://pastebin.com/jK06vqrV How to test I didn’t care about names of more suitable variables.
– Luis Renato H. Jr.
Run a quick test on the Chrome console, put this code and enter:
$('input[name=inputData]')
at least it must show all elements (has more than one with that name) selected. There is no way to give aval()
in an array, you need to specify which element is or traverse it.– rray
I did and returned this. $('input[name=inputData]') Object[]
– Luis Renato H. Jr.
I did it for firebug
– Luis Renato H. Jr.
You did so:
console.log($("input[name='inputData']"));
?– rray
I did so returning **console.log($("input[name='inputData']"); Undefined **
– Luis Renato H. Jr.
When I put : $('.cbhoraini option'). eq(0). val(); in debug and ask to rotate it brings me the first value , if include another date with schedule, and change from eq(0) to eq(1) it does not take the value
– Luis Renato H. Jr.