Answer the question
In order to leave comments, you need to log in
Multiple datePicker on same page in dynamic form not working, why?
The page has a dynamic form where multiple datePicker widgets are created
<?= $form->field($modelAddress, "[{$i}]date")->widget(\yii\jui\DatePicker::className()) ?>
<input type="text" id="ordertemplate-0-date" name="OrderTemplate[0][date]" class="hasDatepicker" aria-invalid="true">
......
<input type="text" id="ordertemplate-1-date" name="OrderTemplate[1][date]" aria-invalid="true">
Answer the question
In order to leave comments, you need to log in
Good afternoon.
In order for all added DatePickers to work, you must first forcibly remove the dataPicker, and then re-initialize all visible widgets, forcibly.
It looks like this:
echo $form->field($model, '[0]date')->widget(DatePicker::className(),[
'options' => [
'data' => [
'picker' => 'datepicker'
]
]
])
$('#plus').on('click', function(){
/* какой-то Ваш код */
$('#testForm')..find('.hasDatepicker').datepicker('destroy');
$('#testForm').find('input[data-picker=datepicker]').datepicker();
/* какой-то Ваш код */
})
1) use different IDs (you have them)
2) run a datepicker on each new instance.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question