I have wbraganca dynamic forms working in Yii2, but I need to add a little function to multiply 2 fields and put value in a third, and do that in every new dynamic form (suppose field 1 is price, field 2 is amount and field 3 is total). With the code I have I'm able to do that but only on the first dynamic form.
<?php
$script = <<< JS
$('#itemsfactura-{$i}-cantidad').change(function(){
var cantidad = $(this).val();
var precio = $('#itemsfactura-{$i}-precio').val();
$('#itemsfactura-{$i}-total_item').val(cantidad * precio);
});
JS;
$this->registerJs($script);
?>
This is the code for the dynamic form fields:
...
<div class="row">
<div class="col-sm-4">
<?= $form->field($modelItemFactura, "[{$i}]precio")->textInput(['maxlength' => true]) ?>
</div>
<div class="col-sm-4">
<?= $form->field($modelItemFactura, "[{$i}]cantidad")->textInput(['maxlength' => true]) ?>
</div>
<div class="col-sm-4">
<?= $form->field($modelItemFactura, "[{$i}]total_item")->textInput(['maxlength' => true]) ?>
</div>
</div>...
Form
JS