Set a Value On PreSubmit

Set a Value On PreSubmit

dianeinfloridadianeinflorida Posts: 8Questions: 3Answers: 0
edited October 2015 in Editor

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

Answers

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin
    Answer ✓

    Hi,

    preSubmit will pass in the data that is being submitted to the server, so if you are going to use preSubmit to perform this action you would be better off using that data (loop over the data 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

This discussion has been closed.