Hi,
I have problem with change value in textfield by button setDefault.
After I clicked on this button I cant access and change value in the name textfield above the button on the "Martin".
I set id "idN2" for this, but nothing happend.
PLEASE , HELP ME.
VIEW:
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // the maximum times, an element can be cloned (default 999)
'min' => 0, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $modelsAddress[0],
'formId' => 'dynamic-form',
'formFields' => [
'name',
],
]); ?>
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-envelope"></i> Test
<button type="button" class="pull-right add-item btn btn-success btn-xs"><i class="fa fa-plus"></i> Add name</button>
<div class="clearfix"></div>
</div>
<div class="panel-body container-items"><!-- widgetContainer -->
<?php foreach ($modelsAddress as $index => $modelAddress): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<span class="panel-title-address">Names: <?= ($index + 1) ?></span>
<button type="button" class="pull-right remove-item btn btn-danger btn-xs"><i class="fa fa-minus"></i></button>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
$testr=5;
// necessary for update action.
if (!$modelAddress->isNewRecord) {
echo Html::activeHiddenInput($modelAddress, "[{$index}]id");
}
?>
<?= $form->field($modelAddress, "[{$index}]name")->textInput(['maxlength' => true,'id'=>"idN2"]) ?>
<button type="button" onclick="setDefaultF($(this))" class="pull-right setDefault btn btn-success btn-xs"><i class="fa fa-plus"></i> SetDefault</button>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php DynamicFormWidget::end(); ?>
$this->registerJs('
function setDefaultF(obj){
$(\'#idN2\').val("Martin");
}
', \yii\web\View::POS_HEAD) ?>