Trigger script if a value has changed in a field between when Editor being spawned to when updated?

Trigger script if a value has changed in a field between when Editor being spawned to when updated?

imarderimarder Posts: 12Questions: 5Answers: 2

When the Editor is spawned in Edit mode, I need a way of determining if a value has changed in a date field to another value after an update. I need to ultimately trigger a PHP script, this of course can be done via ajax, if need.

Is this best done, through the Editor events listener, like somehow comparing before and after values (I am not sure how to do that) or through DB queries and some magic in the table.???.php script? Again, not sure how to do that.

Thanks

Answers

  • imarderimarder Posts: 12Questions: 5Answers: 2

    Ignore and self answered. Found exactly what I was looking for

        var openVals;
        editor
            .on( 'open', function () {
                // Store the values of the fields on open
                openVals = JSON.stringify( editor.get() );
            } )
            .on( 'initSubmit', function () {
                closeVals = JSON.stringify( editor.get() );
                if ( openVals !== closeVals ) {
                       // read the required obj and execute script
                       console.log (closeVals);
                }
            } );
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    That will do nicely :). dependent() would be another option to know when a value gets changed.

    Allan

This discussion has been closed.