I have a datatable where I have the option to edit the date of every record in that table, so I need to use “document on focus” event to get all my datepickers to work. The problem here is that my datepicker only works when I click on the input, if I click in the “icon” it doesn´t work.
This is my datepicker in the form:
JavaScript
x
10
10
1
<div class="form-group">
2
<label for="fecha" class="col-form-label">Fecha</label>
3
<div class="input-group date" id="datepickerEditT" data-target-input="nearest">
4
<input type="text" id="datepickerEditT" name="fechaTratamiento" value="{{date('d/m/Y',strtotime($fecha))}}" class="form-control datepicker-input" data-target="#datepickerEditT" required/>
5
<div class="input-group-append" data-target="#datepickerEditT" data-toggle="datepickerEditT">
6
<div class="input-group-text"><i class="fas fa-calendar-alt"></i></div>
7
</div>
8
</div>
9
</div>
10
and this is the javascript:
JavaScript
1
9
1
$(document).on("focus", "#datepickerEditT", function () {
2
$(this).datepicker({
3
format: "dd/mm/yyyy",
4
language: "es",
5
autoclose: true,
6
todayHighlight: true,
7
});
8
});
9
if I dont use on focus event my datepicker works fine, doesn´t matter if I click on the input or the icon, but I need to use this event because if I dont, my datepicker will only works on the first record in the table.
Advertisement
Answer
I used class div instead of the id like someone said and now everything its working without using the focus event.
JavaScript
1
7
1
$(".datepickerEditT").datepicker({
2
format: "dd/mm/yyyy",
3
language: "es",
4
autoclose: true,
5
todayHighlight: true,
6
});
7