Set a Value On PreSubmit
Set a Value On PreSubmit
dianeinflorida
Posts: 8Questions: 3Answers: 0
I am trying to set a Value on Presubmit. Maybe there is an easier way to do this then preSubmit. I would like to total the values of 3 fields and add it to a "total field". I using the most recent version of editor and datatables. I am using php.
The Console Log shows the values. Do I need to add something to my server script?
editor.on( 'preSubmit', function ( ) {
var m;
var totalMiles=Number(editor.field( 'aaExpenses.milesReimburse' ).val());
var totalTolls=Number(editor.field( 'aaExpenses.tolls' ).val());
var totalParking=Number(editor.field( 'aaExpenses.parking' ).val());
var totalAll = 0;
totalAll += totalTolls;
totalAll += totalParking;
totalAll += totalMiles;
console.log('TOTAL.miles from form............'+totalMiles);
console.log('TOTAL.tolls from form............'+totalTolls);
console.log('TOTAL.parling from form............'+totalParking);
console.log('TOTAL.............'+totalAll);
editor.field( 'aaExpenses.total' ).val( totalAll);//I have also tried editor.field( 'aaExpenses.total' ).set( totalAll);
} );
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
preSubmit
will pass in the data that is being submitted to the server, so if you are going to usepreSubmit
to perform this action you would be better off using that data (loop over thedata
property to get the data for each row being submitted).However, I would actually recommend not doing this on the client-side, but rather do it on the server-side. The server will have all of the information required and if you are using the PHP libraries for Editor (or the .NET ones) you can use the
preEdit
/preCreate
server-side events to easily perform this kind of calculation - it also makes it more secure, since if it were sent from the client, it would be trivial for someone to submit invalid data (if they were so inclined...).Allan