0

I have a row with 2 fields in activeForm (for example Date1 and Date2 fields). These fields are DatePicker (Kartik) When the page loaded this fields working normally when clicking the fields opened DatePicker widget. I have ADD ROW button in the bottom of this row. When I click to ADD ROW, must append new row with 2 fields (Date 1, Date 2) to form. How I do this, when clicking to this button I append renderPartial view to the form. Problem: when new fields appended, DatePicker not working. And I know the reason but I don't know how to use it correctly.

JS Code:

if($(document).on('click','#add-new-edu',function() {
  $('#education').append('$edu_render')
}));

renderPartial variable in Controller:

$edu_render = $this->renderPartial('edu');

renderPartial view:

<div class="row">
<div class="col-lg-2">
    <div class="form-group">
        <label class="control-label">Date 1</label>
        <?=DatePicker::widget([
            'name' => 'enter_date',
            'options' => ['id' => 'id1'],
        ]);?>
    </div>
</div>
<div class="col-lg-2">
    <div class="form-group">
        <label class="control-label">Date 2</label>
        <?=DatePicker::widget([
            'name' => 'enter_date',
            'options' => ['id' => 'id2'],
        ]);?>
    </div>
</div>
<div class="text-center">
    <button type="button" class="btn btn-danger delete-edu">DELETE</button>
</div>

4
  • You have the same id in each row??? Commented Dec 9, 2018 at 16:30
  • Different IDs. I know here problem. When the page loaded DatePicker is inited. When click to add new ROW, the new date picker fields are not inited when the page loaded, because of this, the new date picker fields are not working. I know the problem, but don't know how to fix this problem. Commented Dec 9, 2018 at 17:31
  • But your render partial .. contain options with fixed id .(id1, id2). are your sure you have different id for each new datepicker ??? Commented Dec 9, 2018 at 19:36
  • Yes, different ID. I understand what you did mean. It is not working even first time when appended fields with this IDs (id1, id2) Commented Dec 10, 2018 at 8:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.