preSubmit not cancelling the submit when returning false
preSubmit not cancelling the submit when returning false
B.Redd
Posts: 3Questions: 0Answers: 0
We've discovered that the submit event is not cancelling with the preSubmit event when the function returns false. Please see the example. Has anyone else run into or found a solution for this?:
const clientSideValidation = (editor, columnFields) => {
const handlePreSubmit = (e, data, action) => {
return false;
};
editor.on("preSubmit", handlePreSubmit);
};
export default clientSideValidation;
Replies
I haven't been able to reproduce this issue I'm afraid. If you go to this example and pop open the console and enter:
it will prevent all submissions from Editor.
Can you give me a link to a test page showing the issue please?
Regards,
Allan
Hey, I fixed it! It was a simple fix, and I think I understand the reason for the error, now, though I would be interested in your feedback to confirm.
We have 2 separate preSubmit calls--essentially:
•"editor.on("preSubmit", clientSideValidation);" followed by
•"editor.on("preSubmit", dataToDRFStructure);" calling 2 separate functions.
The first one is for validation and the second for converting the data to Django Rest Framework format.
The fix was to simply switch the order of the calls. I suspect that the validation was having the preSubmit return false and then the data conversion was having it return true, overriding the first call, and that's why the form submission wasn't canceled.
Should we only have one preSubmit call as a best practice?
Ah. Actually, I think Editor should halt the submission if any of the
preSubmit
event handlers returns false. The idea of event handlers is that you should be able to have as many as you want.Allan