Currently, the Forms 2.0 JS 'form' object has an attached `onSuccess` callback/handler, but no `onError` handler. Considering that the form submission is making an asynchronous request, it stands to reason that there should be a callback available to deal with error responses. Upon further investigation I found that an `onError` callback method actually exists in the Forms 2.0 JS (line #3901 of {{instance}}.marketo.com/js/forms2/js/forms2.js), it just isn't bound to the 'forms' object and thus is not available publicly.
var onError = function (){
//TODO: What should happen if the form submission fails?
log(arguments);
if(priv.submitButton){
var btn = priv.submitButton.find("button");
btn.removeAttr('disabled');
btn.html(formData.ButtonText || formData.SubmitLabel || "Submit")
}
}
My suggestion here is to add `priv.onError = []` in the JS, bind the onError method to the forms object so customers can use it, then modify the onError method to handle callback like this:
var onError = function (values, followup){
$.each(priv.onError, function (i, errorFn){
errorFn(values, followup)
});
};
I'm curious if there is a specific reason that this error handler isn't available, in general it's considered best practice in Javascript to have both success and error callbacks for deferred requests.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.