Editor call external function from preSubmit
Editor call external function from preSubmit
rldean1
Posts: 141Questions: 66Answers: 1
I'm doing form validation in preSubmit()
. I want to check two columns for a constraint violation, and I figured this is the best spot to do it. I'm using straight-up JS/jQuery and SQL (no PHP).
Can I stop preSubmit()
, run my function, and then proceed with submission from that function?
editor.on('preSubmit', function (e, data, action) {
if (action !== 'remove') {
//client-side validation of the fields
}
//If any error was reported, cancel the submission so it can be corrected
if (this.inError()) {
return false;
}
//stop form from submitting
return false;
//call my special function
someSpecialFunction(data)
});
function someSpecialFunction(x) {
// SQL was called, this function processes the returned info
// {jsonResponse} from server looks like:
// {"error", "This is a general error"}
// set the error:
editor.error("This is a general error")
editor.inError()
/**
* if there isn't an error, allow preSubmit to finish ???
* something like...
*/
if (!editor.inError()) {
editor.submit() //???????
}
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Yes, this is possible, but you need to use a little "trickery" since the
submit()
call will always trigger thepreSubmit
event. The way to do it is to add a flag that will stoppreSubmit
's event handler from returningfalse
- example:Allan