Latest Editor onPreClose is missing Trigger parameter

Latest Editor onPreClose is missing Trigger parameter

lowrymellowrymel Posts: 20Questions: 4Answers: 0

In the previous version of Editor there was a Trigger parameter to identify the Close Event Action.
https://www.editor.datatables.net/release/DataTables/extras/Editor/docs/Editor.html#onPreClose

onPreClose

Before a form is closed, this event is fired. It allows the close action to be cancelled by returning false from the function. This can be useful for confirming that the user actually wants to close the display (if they have unsaved changes for example).

Parameters:
    Name    Type    Attributes  Default     Description
1
    e   event           

jQuery event object
2
    trigger string          

Action that caused the close event - can be undefined. Typically defined by the display controller.

The latest version of Editor does not have the trigger parameter
https://editor.datatables.net/reference/event/preClose

Parameters:
Name Type Optional Description
1 e

objectJS
    No  

jQuery event object

Returns:

booleanJS

Return false to stop the close from happening. This will leave the form in the same state that it previously was.

Would anyone have a brief example showing how to use the new preClose in the same fashion as the old one shown below.?

        editor_task.on('onPreClose', function ( e, trigger ) {
            var changed = false;
            $.each( editor_task.get(), function ( key, val ) {
                if ( openVals[key] !== val ) {
                    changed = true;
                }
            } );
            // A 'false' return will cause the close operation to be cancelled. When the
            // trigger is 'submit' the close command came from the form submission!
            if ( changed && trigger !== 'submit' ) {
                return confirm( 'You have unsaved changes. Are you sure you want to exit?' );
            }
        } );

Thanks in advance.

This question has an accepted answers - jump to answer

Answers

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

    Hi,

    That's correct - apologies I should have made this more clear in the release notes.

    The trigger option has basically been replaced with the new blur functionality. A blur will occur when you might want to close the display - i.e. clicking on the background of the modal. A close will occur when the user is saying directly that they want to close the form (i.e. clicking on the close button).

    So you probably want to use the preBlur event to perform the unsaved changes check. There is an updated example available here.

    Regards,
    Allan

  • lowrymellowrymel Posts: 20Questions: 4Answers: 0

    Sorry but that did not work for me. I will get a test case available in the next couple of days. Thanks for the extraordinary support!

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

    Perhaps if you could show me your code I might be able to understand the problem and suggest a fix.

    Thanks,
    Allan

This discussion has been closed.