You’re using the same reference for every data-target, they probably need to be unique for each row
May 23, 2022
5
Level 1
datetimepicker not working in loop
I show data in table with foreach and for each data I open a modal in the table. inside this model there is a datetimepicker. When I open the first modal, the datetimepicker works perfectly, but when close that modal and open another modal, the datetimepciker doesn't work. Where am I missing? Button to trigger modal
<a data-toggle="modal" data-target="#modalCart{{$result->orderId}}" class="orderNumber" >{{$result->orderNumber}}</a>
Modal
.
.
.
<div class="card-body collapse show" id="accordion4">
<form action="{{route('create-label')}}" method="post">
@csrf
<label class="control-label" for="WeightLbs">Ship Date</label>
<div class="input-group date" id="reservationdate" data-target-input="nearest">
<input type="text" name="shipDate" id="shipDate" class="form-control datetimepicker-input inputs" data-target="#reservationdate">
<div class="input-group-append" data-target="#reservationdate" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
<div class="modal-footer mt-3" >
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
.
.
.
jQuery script
$(function () {
$('#reservationdate').datetimepicker({
format: 'YYYY/MM/DD',
minDate: new Date(),
defaultDate: new Date(),
});
})
Please or to participate in this conversation.