Append renderPartial to view with JS - Yii2

232 views Asked by At

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>

0

There are 0 answers