How to control call to "alert" method with hidden form editor and error on submit?
How to control call to "alert" method with hidden form editor and error on submit?
Hello!
I use a hidden editor to submit values obtained by other means.
When a validation error is returned from our API, we would like to handle how to display the error message ourself.
The current behaviour for Editor is to show the error by calling Window "alert" method when the form error's dom element is not visible.
Example of using a hidden Editor
editor
.edit(selected.indexes(), false)
.set('email', newEmail)
.submit(success => handleSuccess(success), error => {
handleAndShowError(error)
})
Editor v2.4.2 source code "problem"
In function error$1(name, msg)
Line 2358
// ... line 2365
if (name && !$(this.dom.formError).is(':visible')) {
// Don't have a global error element visible, so flash it up as an alert
alert(name.replace(/<br>/g, '\n'));
}
// ...
How can this be fixed...
Should this code simply be removed? (I tend to think so)
Should a new Editor form parameter be introduced?
Or did I miss something?
Thank you for your help!
This question has an accepted answers - jump to answer
Answers
Hi,
Yes, if you are happy just commenting that line out, that is what to do. There isn't a configuration option at this time to disable that behaviour when the error element is not visible I'm afraid.
Allan
Ok! That's what I'll do for now. Thanks.
Removing the behaviour feels like the correct way a hidden editor should behave. But at the same time, it would break the way it works already; users could rely on it...
JY
Yes, the problem with removing is that it requires the develop using it to implement their own error reporting system, otherwise it's might not see an error. It should probably be pluggable to allow that to be done easily. Thanks for flagging that up.
Allan