I working on Yii2 app with advanced template. There is several fields on my tabular form(kartik extension). first field is Qty (textinput), second field is price (textInput) with yii masking input and third is total textInput with readonly attribute. So, I wanted to fill third textInput automatically right after I have filled first textinput and second textinput with MaskedInput with out rounding my price and total field.
if i not set radixPoint, groupSeparator,autoGroup
7360
if i set radixPoint => ‘,’ groupSeparator => ‘.’ autoGroup=>true
7359
here’s my code :
$js = <<<JS
function goodsTotal(val,attr,index){
var qty,price;
if (attr == 'price') {
qty = $('#askgoods-'+index+'-qty').val();
price = val;
}
if (attr == 'qty') {
price = $('#askgoods-'+index+'-price').val();
qty = val;
}
var total = parseFloat(qty) * parseFloat(price);
t = parseFloat(total);
// var formattotal = 'Rp' + total.toFixed(0).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1.");
// $('#askgoods-'+index+'-totalshow').val(formattotal);
$('#askgoods-'+index+'-total').val(t);
}
$('#add-ask-goods .kv-batch-create').on('click',function(){
var baris = $('input[id$=-name]').length;
$.when( addRowAskGoods() ).done(function() {
$('#askgoods-'+baris+'-name').focus();
});
});
function goodsTotalmodal(val,attr,index){
var qty,price;
if (attr == 'price') {
qty = $('#askgoodsmodal-'+index+'-qty').val();
price = val;
}
if (attr == 'qty') {
price = $('#askgoodsmodal-'+index+'-price').val();
qty = val;
}
var total = parseFloat(qty) * parseFloat(price);
t = parseFloat(total);
// var formattotal = 'Rp' + total.toFixed(0).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1.");
// $('#askgoods-'+index+'-totalshow').val(formattotal);
$('#askgoods-'+index+'-total').val(t);
}
// $('#add-ask-goods-modal .kv-batch-create').on('click',function(){
$('body').on('click','#add-ask-goods-modal .kv-batch-create',function(){
var baris = $('input[id^=askgoodsmodal-][id$=-name]').length;
$.when( addRowAskGoodsmodal() ).done(function() {
$('#askgoodsmodal-'+baris+'-name').focus();
});
});
JS;
.....
'qty' => [
'type' => TabularForm::INPUT_WIDGET,
'widgetClass'=>\yii\widgets\MaskedInput::className(),
'options' => function($modelGoods,$key) use ($modal){
return [
'clientOptions'=>[
'alias'=>'decimal',
],
'options'=>[
'class'=>'form-control',
'onkeyup'=>'goodsTotal'.$modal[1].'(this.value,"qty",'.$key.')',
'autocomplete'=>'off'
],
];
},
],
'price' => [
'type' => TabularForm::INPUT_WIDGET,
'format'=>['decimal',2],
'widgetClass'=>\yii\widgets\MaskedInput::className(),
'options' => function($modelGoods,$key) use ($modal){
return [
'clientOptions'=>[
'alias'=>'decimal',
],
'options'=>[
'class'=>'form-control',
'onkeyup'=>'goodsTotal'.$modal[1].'(this.value,"price",'.$key.')',
'autocomplete'=>'off'
],
];
},
],
'total' => [
'type' => TabularForm::INPUT_WIDGET,
'widgetClass'=>\yii\widgets\MaskedInput::className(),
'options' => [
'clientOptions'=>[
'alias'=>'decimal',
'digits' => 0,
'digitsOptional' => false,
'radixPoint' => ',',
'groupSeparator' => '.',
'autoGroup' => true,
'removeMaskOnSubmit' => true,
],
'options'=>[
'readonly'=>true,
'class'=>'form-control',
'tabindex'=>'1',
],
],
am i wrong using yii2 masking input ? or there are other wrong if i use masked input with tabular Form ?