Hello Guys,
I have a Sales form that was created using yii2-dynamicform which is forming fine. but I want to be able to pass the unit price of a product selected to corresponding input field that is also added dynamically, how do i add the id of input element to select2 dynamically base on the numbers of record?
from what i ahve done so far, it keeps updating the unit price of the first row only
'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' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $BranchSales[0],
'formId' => 'dynamic-form',
'formFields' => [
'pump',
'product_material_name',
'attendant',
'amount',
'qty',
],
]); ?>
= $form->field($SalesEntries, "[{$index}]product_material_name")->widget(Select2::classname(), [
'data' =>ArrayHelper::map(GoodsProducts::find()->where(['branch_code'=>Yii::$app->user->identity->branch_code])->asArray()->all(), 'product_material_code', 'product_material_name'),
// ['prompt'=>'-Choose a Product-'],
'language' => 'en',
'id' => '[{$index}]product_material_name',
'options' => [
'prompt' => 'Select Product',
'onchange'=>'
$.post( "'.urldecode(Yii::$app->urlManager->createUrl('branch-sales/list&id=')).'"+$(this).val(), function( data ) {
$( "Input#branchsales-'.$index.'-u_price" ).val(data); //here is where am having issues, it keeps updating the first one only
});
']
]);
?>
Hello Guys, I have a Sales form that was created using yii2-dynamicform which is forming fine. but I want to be able to pass the unit price of a product selected to corresponding input field that is also added dynamically, how do i add the id of input element to select2 dynamically base on the numbers of record? from what i ahve done so far, it keeps updating the unit price of the first row only
Attendant = ($index + 1) ?>