Want to change elements data before it goes to the server.

Want to change elements data before it goes to the server.

A.obj.sys.incA.obj.sys.inc Posts: 14Questions: 7Answers: 4

I have looked at several examples using

editor.on('preSubmit', function(e, o, action)

but I am having problems selecting the element in the out going data array. The following is my function.

editor.on('preSubmit', function(e, o, action) {
    if (action == 'edit') {
        var testParameters = editor.field('t.test_parameters');                 
        if (testParameters != null ){
          console.log("tp: " + testParameters.val());                       
          var temp = testParameters.val().split("=").join("/");//replace all = with /.
          console.log("temp: " + temp);                     
          //editor.field('t.test_parameters' ).val(temp);
          o.data.test_parameters = temp ;
          console.log(o);
        }
    }
});

Everything is just fine at the beginning where I get the editor's field. testParameters is populated properly. I then alter the data and that is fine. I want to update the same field but

o.data.test_parameters = temp ;

adds an element to the data array. Stupid me I tried the following

o.data.t.test_parameters = temp ;

but this does not work because this is not the right syntax to update the element. Would somebody be so kind and tell me how I should update the t.test_parameters value in the o.data array. Help would be much appreciated.

This question has an accepted answers - jump to answer

Answers

  • A.obj.sys.incA.obj.sys.inc Posts: 14Questions: 7Answers: 4
    Answer ✓

    I expanded my search and found the following link

    https://www.datatables.net/forums/discussion/30440/strange-behaviour-of-on-presubmit
    

    I changed my code in the editor.on('preSubmit') so that it uses the following code.

      $.each( o.data, function ( key, value ) {
        var t = o.data[key].t.test_parameters ;
        t = t.split("=").join("/");//replace all = with /.   
        o.data[key].t.test_parameters = t;
      } );
    

    This works just fine. Hope this helps others. Please close.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    Good to hear you found the solution. The loop is required because of Editor 1.5's multi-row editing ability. The data format is detailed in the client / server communication documentation.

    Allan

This discussion has been closed.