HI all,i’m trying to put in an DynamicFormWidget a autocomplete (
i’mcreating a basic form to create documents like an invoice)
the code :
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<i class="glyphicon glyphicon-briefcase"></i> Items
<button type="button" class="add-item btn btn-success btn-sm pull-right"><i class="glyphicon glyphicon-plus"></i> Add</button>
</h4>
</div>
<div class="panel-body">
<div class="container-items"><!-- widgetBody -->
<?php foreach ($items as $i => $m): ?>
<div class="item"><!-- widgetItem -->
<div class="rows">
<?php
// necessary for update action.
if (! $m->isNewRecord) {
echo Html::activeHiddenInput($m, "[{$i}]id");
}
?>
<table width="80%">
<tr>
<td valign="top" width="5%"><button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button></td>
<td width="25%">
<?= $form->field($m, "[{$i}]itcode")->
widget(AutoComplete::className(),
['name' => '[{$i}]itcode',
'id' => "[{$i}]itcode",
'clientOptions' => [
'source' => $datam,
'autoFill'=>true,
'select' => new JsExpression("function( event, ui ) {
$('#invoice-[{$i}]itcode').val(ui.item.id);
//#City-state_name is the id of hiddenInput.
}"),
'onchange' => new JsExpression("function( event, ui ) {alert((ui.item.label))}")
],
])->label(false) ?></td>
<td width="50%"><?= $form->field($m, "[{$i}]item")->textInput(['maxlength' => true,'placeholder'=>'description'])->label(false) ?></td>
<td width="10%"><?= $form->field($m, "[{$i}]qty")->textInput(['maxlength' => true,'placeholder'=>'qta'])->label(false) ?></td>
<td width="15%">
<?php echo $form->field($m, "[{$i}]total")->textInput(['placeholder'=>'price'])->label(false);?>
</td>
</tr>
</table>
</div><!-- .row -->
</div>
<?php endforeach; ?>
</div>
</div>
</div><!-- .panel -->
<?php DynamicFormWidget::end(); ?>
the problem is that the autocomplete works only in the first row in the second row the field [{$i}]itcode
lost is class and return to be a simple text field
any tips?
tks all