editor.mode() is null on submitComplete event

editor.mode() is null on submitComplete event

FurburgerFurburger Posts: 37Questions: 8Answers: 0

Hi Allan

I notice that editor.mode() is null on submitComplete

I am trying to use this event to jump to the inserted row after a row insert (as you advised).

How else can I determine what mode the form was in when this event is triggered?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Good point. submitComplete is triggered once the form has been cleaned up, so Editor is no longer in an editing mode (hence why mode() is null).

    Instead, what you could do is use the third parameter passed into the event handler to get the action object from it:

    editor.on( 'submitComplete', function ( e, json, data ) {
      if ( data.action === 'create' ) {
        ...
      }
    } );
    

    The data parameter is the data submitted to the server, so action must be there.

    Allan

  • FurburgerFurburger Posts: 37Questions: 8Answers: 0

    The Editor is submitting "action" to the server, but it is not in the data object returned by the submitComplete

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Answer ✓

    I was wrong - sorry! My own documentation notes that the third parameter pass in to the event is not in fact the submitted data!

    Instead, what I would recommend is that we chain a couple of events:

    editor.on( 'postSubmit', function ( e, json, data, action ) {
      editor.one( 'submitComplete', function () {
        //... make use of `action`
      } );
    } );
    

    So basically we make use of postSubmit, which does have the action parameter, to add one submitComplete event handler (note the use of one() rather than on() for the inner event handler), and we can use the action in there as it forms a closure.

    Regards,
    Allan

  • FurburgerFurburger Posts: 37Questions: 8Answers: 0

    Great - thanks. Works like a charm.

This discussion has been closed.