A
A
akula222018-02-16 14:28:03
Yii
akula22, 2018-02-16 14:28:03

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()) ?>

the first widget works, the others don't, you can't select a date.
in the source of the page it turns out like this
<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">

for some reason class="hasDatepicker" disappears, I tried to prescribe it explicitly, it still doesn't help, and is this the cause of the problem?
Maybe someone knows how to solve this crap, tried the widget from Katrik, the same thing, the first one works, the rest do not (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-02-17
@akula22

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'
                    ]
                ]
         ])

and below, or in a separate file, there will be such js code:
$('#plus').on('click', function(){
       /* какой-то Ваш код */
       $('#testForm')..find('.hasDatepicker').datepicker('destroy');
       $('#testForm').find('input[data-picker=datepicker]').datepicker();
       /* какой-то Ваш код */
    })

I had to add the parameter "data-picker" because "destroy" removes the class "hasDatepicker"

D
Dmitry Bay, 2018-02-16
@kawabanga

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 question

Ask a Question

731 491 924 answers to any question