K
K
Konstantin Zhikhor2018-02-26 22:34:59
Yii
Konstantin Zhikhor, 2018-02-26 22:34:59

how to make multiple datepicker in yii2?

Hello, I need your help. I have a form to fill out a plan. This plan includes milestones. The stages consist of a description title and a date. problem with filling in the date. the first time the datepicker works, but the subsequent ones do not, I need it to work for the next steps. What should I do.
form screen form
5a9461363c122964123601.png
code

<div class="ag_1_1">
      <div class="ag_3">План достижения цели</div>
      <div class="stage">
      <div class="ag_1_2"><?= $form->field($stage, '[]title')->textInput(['class'=>'input_goal','placeholder'=>'Название этапа'])->label(false) ?></div>
      
      <div class="ag_1_2"><?= $form->field($stage, '[]description')->textarea(['class'=>'input_goal','placeholder'=>'Описание этапа'])->label(false) ?></div>
        <ul class="ag_8">
          <li class="ag_l"><img src="img/icon/leveldown.svg" alt=""/></li>
          <li class="ag_ac"><?= $form->field($stage, '[]date_finish_stage')->widget(BootstrapDatepicker::className(['type'=>BootstrapDatepicker::TYPE_RANGE]))->label() ?></li>
        </ul>
                
        </div>
        <div class="ag_2_1" onclick="$('.ag_1_1').find('.stage').append($('.stage').html());">Добавить этап</div>
      </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-02-26
@slo_nik

Good evening.
You need to re-initialize the calendars each time you add the DatePicker.
Something like this:

// сначала удаляем все datepicker
form.find('.hasDatepicker').datepicker('destroy');
// затем заново всё инициализируем
$('#testForm').find('input[data-picker=datepicker]').datepicker()

The example showed for the built-in datepicker in yii2, but you have a similar solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question