New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form Fires on Error #71
Comments
It looks like you have a syntax error in your callback function
I don't think evt is defined. It should be event. You should open your browsers debugging window to see if any errors are being printed out. |
Hi Rick, I actually thought that was suspect myself but I copied and pasted this off your documentation. On http://rickharrison.github.io/validate.js/, you have the following code: <script type="text/javascript">
new FormValidator('example_form', [{
name: 'req',
display: 'required',
rules: 'required'
}, {
name: 'alphanumeric',
rules: 'alpha_numeric'
}, {
name: 'password',
rules: 'required'
}, {
name: 'password_confirm',
display: 'password confirmation',
rules: 'required|matches[password]'
}, {
name: 'email',
rules: 'valid_email'
}, {
name: 'minlength',
display: 'min length',
rules: 'min_length[8]'
}, {
name: 'tos_checkbox',
display: 'terms of service',
rules: 'required'
}], function(errors, evt) {
var SELECTOR_ERRORS = $('.error_box'),
SELECTOR_SUCCESS = $('.success_box');
if (errors.length > 0) {
SELECTOR_ERRORS.empty();
for (var i = 0, errorLength = errors.length; i < errorLength; i++) {
SELECTOR_ERRORS.append(errors[i].message + '<br />');
}
SELECTOR_SUCCESS.css({ display: 'none' });
SELECTOR_ERRORS.fadeIn(200);
} else {
SELECTOR_ERRORS.css({ display: 'none' });
SELECTOR_SUCCESS.fadeIn(200);
}
if (evt && evt.preventDefault) {
evt.preventDefault();
} else if (event) {
event.returnValue = false;
}
}); I changed mine to follow your example above and now it works. Should event read evt? |
That should work. Have you tried it? Also, where did you copy and paste it from. Did you view the source to copy/paste it? |
I tried it, it worked and I copied and pasted it from the source of http://rickharrison.github.io/validate.js/. I'm just not sure if you're using event for browser compatibility or if its a typo. |
So the second if block still uses event, because that is a global keyword in internet explorer browsers. IE uses event.returnValue to prevent submission of the form. |
Thanks, that clarifies everything for me. I'll close this issue. |
Hey Rick,
Great library and precisely what I was looking for. I'm having an issue where the form is being submitted even though there is an error firing. Essentially, I leave the form blank, I click submit, validation occurs and adds an error message but it continues to post anyways. Any idea what I'm doing wrong?
validate-rules.js
Any idea what I'm doing wrong?
The text was updated successfully, but these errors were encountered: