Create a function if something is really edited

Create a function if something is really edited

rainolfrainolf Posts: 56Questions: 6Answers: 0
edited May 2014 in Editor

Hello,
i'm just working on editor in order to create a function when a filed is really edited.

So i'm thinking about on initEdit event to retrieve the data field then call Edit event to launch the function.

Something like that:

 editor.on('initEdit', function () {
    oTable = $('#meetings').dataTable();
    var sData1 = oTable.fnGetData(this.s.editRow);
    Now how can i retrieve the current field value??? 
    });
    editor.on('onEdit', function () {
    oTable = $('#meetings').dataTable();
    var sData2 = oTable.fnGetData(this.s.editRow);
       Now how can i retrieve the current field value??? 
       // Something here to check if the value is changed???
    jQuery.ajax({
        type: 'POST',
        url: "../pages/email.php", //Here i need to pass modified value..how???
        dataType: "json",
        success: function(data){ alert("Email sending status to : " + data.emailto_Part + " = " + data.emailSent); }
      });
    });

Could you help me to complete this code or better suggest me the best way to accomplidh this?

Thank you

Replies

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin

    Now how can i retrieve the current field value???

    Use val() to get (and set) the value of a field. So you might do something like:

    var val = null;
    
    editor
      .on( 'initEdit', function () {
        val = editor.val( 'myField' );
      } )
      .on( 'edit', function () {
        if ( editor.val( 'myField' ) !== val ) {
          alert( 'It changed!' );
        }
      } )
    

    Allan

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    mm..good staring point...

    and is there any smart method that can i use (inside .on( 'edit', function () {) to send to php function all rows value?

    I mean:
    right now in editor i want to show only one filed caller "status".

    When when the edit has been made i would like to pass to php scripts all rows values.

    What do you think about?

    Thank you

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    edited May 2014

    send to php function all rows value?

    The row values are passed in as the third parameter to initEdit events, so you could use that perhaps?

    Allan

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    mmm...could be..

    Could you please post me an example in order to work on it? So i could verify if its what i need.

    Thank you

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    edited May 2014

    Typo in my last comment for link - now fixed.

    editor.on( 'initEdit', function ( e, node, data ) {
      console.log( data );
    } );
    

    Allan

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    oh...good!!

    Thank you very much..

    That's what i was searching for...

    Thank you again

  • rainolfrainolf Posts: 56Questions: 6Answers: 0

    And what about PostEdit events...seems that does not keep the same parameters:
    editor.on( 'initEdit', function ( e, node, data ) {
    console.log( data );
    } );
    Cause i would to pass data when are already updated
    Am i right?

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin

    postEdit provides three parameters - the event, the json from the server and the data used to set the row. That is documented in: postEdit.

    Allan

This discussion has been closed.