Editor losing state after submit, can't submit multiple times

Editor losing state after submit, can't submit multiple times

mommom Posts: 14Questions: 4Answers: 0
edited March 2019 in Editor

I'm using Editor 1.9.0. While in 99% of the cases it is sufficient to close the editor form right after submitting, I have one big form that needs to be filled in in steps, submitting the data after each step and keeping the form open. I have explored various options, and they all turn out unsuccessful.

In particular, the two methods (per the manual) to achieve this are:
a) programmatically call the API method editor.submit(null, null, null, false) - the last parameter set to false should not close the form
b) init the form with formOptions: { main: { onComplete: 'none' } } (The manual refers to closeOnComplete option, but I couldn't find such - maybe it's a deprecated one)

While both methods seem to do their primary goal - Editor submits the form data succesfully and does not close the form afterwards, what happens is that internally it goes out of editing mode and any subsequent call to submit() does nothing - no matter if with the default Save button, with a custom button, with an API call to submit() or even from the console. I attached a number of event listeners and they don't fire (for example: preSubmit)
Calling submit() with callback functions - submit( successFn, errorFn, formatDataFn ) also does nothing - none of the 3 callbacks get executed.

Debugging further, I noticed that while the form is open, before the first submit, editor.mode() returns edit. After the first submit, editor.mode() equals null. So, somehow Editor has gone out of editing mode and I can't figure out how to bring it back without closing and reopening the form.

Has anyone hit such problem, am I doing anything wrong or it's a bug?

Thanks for your help.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,773Questions: 1Answers: 10,112 Site admin

    The manual refers to closeOnComplete option, but I couldn't find such - maybe it's a deprecated one

    Yes. It was generalised to be just onComplete. Thanks for pointing that out.

    Editor submits the form data succesfully and does not close the form afterwards, what happens is that internally it goes out of editing mode and any subsequent call to submit() does nothing

    This is intentional (primarily to ensure that the form is cleared out so data is accidentally submitted later once the form is closed). If you want to start a fresh edit, you can do so by calling the edit() method.

    Allan

  • mommom Posts: 14Questions: 4Answers: 0

    Here's an isolated minimal example demonstrating the issue:
    https://www.rosoft.biz/datatables/editor_submit_issue.html

    Watch the XHR network requests and check editor.mode() in console after clicking on Update button.

  • mommom Posts: 14Questions: 4Answers: 0

    Hi Allan, thank you for your reply.

    But what is the purpose of calling submit() without closing the form then, if the Editor goes out of edit mode? How could one create wizard-like step-by-step forms (in my case the form is using a custom template with bootstrap tabs and I want to ensure all data is saved when switching to another tab, because some of the tabs call serverside updates relying on the saved data).

    Yes, I figured I could call edit() but this goes with visual distortions - hiding the form, then showing it back in, animations and so on... I wish there would be a silent way to just post the form data to the server then continue editing.

  • allanallan Posts: 61,773Questions: 1Answers: 10,112 Site admin
    Answer ✓

    But what is the purpose of calling submit() without closing the form then, if the Editor goes out of edit mode?

    Its for visual continuity if you wanted to immediately start editing another row (or even the same row). This example shows a use for that.

    Yes, I figured I could call edit() but this goes with visual distortions - hiding the form, then showing it back in, animations and so on... I

    That's exactly what the option for not closing the form is for. To stop that visual messing around. You just need to trigger editing again.

    Allan

  • mommom Posts: 14Questions: 4Answers: 0

    Okay, thanks Allan.
    I was using a custom display controller for this particular form - hiding the table and displaying the editor form on the same page, without lightbox modals but with slide animations - and it was acting on second call to edit(). I was able to add a few conditions and it is working as expected now.
    The only downside is that after each intermediate submit/edit a whole bunch of ajax requests do happen again - reloading the form and all dependent fields. I can live with that, yet I still believe it would be nice to have an option to simply submit the form data without losing state and keep editing the same row. Feature suggestion.

This discussion has been closed.