javascript - Meteor AutoForm - Is it possible to manually call the onSuccess or onError hooks? -
i have form checks user's captcha input. when captcha valid, should send e-mail, otherwise should display error.
autoform.addhooks(["form1", "form2", "form3"], { onsubmit: function(doc) { meteor.call('validatecaptcha', formdata, function(error, result) { if (result.success == true) { meteor.call('sendemail', doc); } else { recaptcha.reload(); // call onerror here console.log("error!"); } }); }, onsuccess: function(operation, result, template) { // display success, reset form status console.log("captcha validation success! email sent!"); }, onerror: function(operation, error, template) { // display error, reset form status console.log("error: captcha validation failed!"); } }
now problem code when user submits correct captcha, code send e-mail not trigger onsuccess()
hook.
the same goes when user submits wrong captcha. displays error message not trigger onerror()
hook.
is there way manually call these hooks?
according autoform hooks documentation, onsuccess
, onerror
called on successful or failed operations, not including onsubmit
:
// called when operation succeeds, operation // "insert", "update", "remove", or method name. onsuccess: function(operation, result, template) {}, // called when operation fails, operation // "validation", "insert", "update", "remove", or method name. onerror: function(operation, error, template) {},
if need handle success/failure cases onsubmit
, should in if (result.success === true) ... else
code directly. handle both success , error cases in after
hooks on per-operation basis, if want more granular control.
Comments
Post a Comment