本文介绍了在 texbox 中传递计算数据而不是来自动态形式 yii2 的任何模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用动态形式 yii2 将两个文本框(数量、比率)的乘积从模型 productsales 获取到第三个文本框(值).它与 Yii2-dynamicforms 和 javascript 完全相同,除了第三个文本框不属于任何模型._形式

<?= $form->field($modelsProductsales, "[{$i}]qty")->label(false)->textInput(['maxlength' => true,'onchange' =>; 'getTotal($(this))', 'onkeyup' => 'getTotal($(this))','onchange' => 'getValue($(this))', 'onkeyup' => 'getValue($(this))','placeholder' => 'Qty']) ?>

<div class="col-xs-1 col-sm-1 col-lg-1 nopadding"><?= $form->field($modelsProductsales, "[{$i}]free")->label(false)->textInput(['maxlength' => true,'onchange' =>; 'getTotal($(this))', 'onkeyup' => 'getTotal($(this))','placeholder' => '免费']) ?>

<div class="col-xs-1 col-sm-1 col-lg-1"><input type="text" class="form-control" id="value">

JS 函数 -

这没有给出任何输出.如果需要任何额外的代码,请告诉我.

解决方案

_form.

<input type="text" class="form-control" id="productsales-<?= $i ?>-value">

JS

if(!isNaN(current) && !isNaN(next)) {总计 = parseInt(current) * parseInt(next);}valueField = "productsales-".concat(index).concat("-value");$("#"+valueField+"").val(total);

I'm trying to get the product of two textboxes (qty, rate) from model productsales to a 3rd textbox (value) withing dynamic form yii2. It is exactly same as Yii2-dynamicforms and javascript, except, the 3rd textbox doesn't belong to any model._form

<div class="col-xs-1 col-sm-1 col-lg-1 nopadding">
                                    <?= $form->field($modelsProductsales, "[{$i}]qty")->label(false)->textInput(['maxlength' => true,'onchange' => 'getTotal($(this))', 'onkeyup' => 'getTotal($(this))','onchange' => 'getValue($(this))', 'onkeyup' => 'getValue($(this))','placeholder' => 'Qty']) ?>
                                </div>
                                <div class="col-xs-1 col-sm-1 col-lg-1 nopadding">
                                    <?= $form->field($modelsProductsales, "[{$i}]free")->label(false)->textInput(['maxlength' => true,'onchange' => 'getTotal($(this))', 'onkeyup' => 'getTotal($(this))','placeholder' => 'Free']) ?>
                                </div>
<div class="col-xs-1 col-sm-1 col-lg-1 ">
                                    <input type="text" class="form-control" id="value">
                                </div>

JS function -

<?

This is not giving any output. Please let me know if any additional piece of code needed.

解决方案

_form.

<input type="text" class="form-control" id="productsales-<?= $i ?>-value">

JS

if(!isNaN(current) && !isNaN(next)) {
    total = parseInt(current) * parseInt(next);
}
valueField = "productsales-".concat(index).concat("-value");

$("#"+valueField+"").val(total);

这篇关于在 texbox 中传递计算数据而不是来自动态形式 yii2 的任何模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 13:06