Calculation On Vtiger Field Before Save Handler On Javascript Side (code Inside)
I need to understand how to do real time calculation on Edit.js By searching and looking around i came up with this code in Edit.js of the Contact Module. calculate_amount: functio
Solution 1:
I should write your keyup function like this:
I tested, it's OK
calculateAmount: function (){
var units = $("input[name='cf_1512']");
var value = $("input[name='cf_1514']");
$(document).on('keyup',"input[name='cf_1512'], input[name='cf_1514']", function(){
if (units.val() != '' && value.val() != ''){
var currentamount = units.val() * value.val();
$("input[name='cf_1518']").val(currentamount);
}
})
},
Solution 2:
You must call you function into the function registerBasicEvents. If the registerBasicEvents function is not available in Edit.js of Contacts module so add it.
registerBasicEvents: function (container) {
this._super(container);
this.calculate_amount();
}
Solution 3:
You should pass id's of element instead reference of element for Keyup function. Please find below code snippet and modify your code in vTiger. As I checked all syntax and function written correctly in your script. Just pass the comma separated id's and execute the code. Thanks!
var units = $('#Contacts_editView_fieldName_cf_1512');
var value = $('#Contacts_editView_fieldName_cf_1514');
$('#Contacts_editView_fieldName_cf_1512, #Contacts_editView_fieldName_cf_1514').on('keyup', function(){
if (units.val() != '' && value.val() != ''){
var currentamount = parseFloat(units.val()) * parseFloat(value.val());
$("#Contacts_editView_fieldName_cf_1516").val(currentamount);
}
});
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
Input1: <inputtype="text"id="Contacts_editView_fieldName_cf_1512"/><br/>
Input2: <inputtype="text"id="Contacts_editView_fieldName_cf_1514" /><br/>
Result: <inputtype="text"id="Contacts_editView_fieldName_cf_1516"/>
Post a Comment for "Calculation On Vtiger Field Before Save Handler On Javascript Side (code Inside)"