-
-
Notifications
You must be signed in to change notification settings - Fork 328
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
Allow removing sticky errors outside of hooks #805
Comments
They do prevent form submission. That is the point of them. The bit about going away when the form is reset just means that they'll disappear if you have a reset button and the user clicks it. But in order to submit successfully, you'll have to remove any sticky errors you've added each time they submit. In general, adding the following in a this.removeStickyValidationError('username');
this.removeStickyValidationError('password'); You may prefer to have those in a Edit: Just realized they can't be in keyup/blur handler since they're only available on the hook context. Maybe we'll have to add a more general API function for removing them. |
Thank you for the quick response and clarification. It looks like function removeStickyValidationError(key) {
delete AutoForm.templateInstanceForForm("loginForm")._stickyErrors[key];
AutoForm.validateForm("loginForm");
}
Template["login"].events({
"change input[name=username]": function () {
removeStickyValidationError("username");
},
"change input[name=password]": function () {
removeStickyValidationError("password");
}
}); This gives me the expected behaviour. Unrelated note for potential readers: I have also tried experimenting with non-sticky errors using the AutoForm.getValidationContext("loginForm").addInvalidKeys([
{name: "username", type: "invalid-username"}
]); However, I could not get this to work reliably. AutoForm appears to validate the form at seemingly random intervals (it probably debounces DOM events in order to not cause delayed UI response). Disabling the "keyUp" validation only helped partially. Long story short, non-sticky errors do indeed not stick and tend to disappear without obvious reason. |
Your workaround is pretty similar to what we'll have to provide, and possibly also a new pre-validation hook. I had tested by clearing the sticky errors in a "before" hook, but in some cases, like when using As far as the other approach, revalidation should be happening only on change, blur, and throttled keyup. But yes, as soon as the first revalidation occurs, you lose any manually added invalid keys. That's why the sticky keys are necessary. |
Release date ?? |
* devel: (143 commits) bump version rearrange and fix Meteor-Community-Packages#831 bump version Fix validation for autoForm's with no type set bump version prevalidate method type forms only when both schema and collection are provided (fix Meteor-Community-Packages#766) change array handling ignore errors due to timing (Meteor-Community-Packages#789) better error for missing form id; fixes Meteor-Community-Packages#776 move beginSubmit hook call to before prevalidation (Meteor-Community-Packages#805) change when formToDoc is called, add formToModifier, and optimize creating doc/mod from form (Meteor-Community-Packages#816) Add orion to community packages Update autoform-api.js Add try/catch to _validateField method Add return to afOptionsFromSchema helper docs docs bump version Meteor 1.0.4 compatibility fixes (closes Meteor-Community-Packages#790; closes Meteor-Community-Packages#794) minor error msg change ... Conflicts: components/autoForm/autoForm.js
Added in 5.7.0 |
For future readers, the latest release allows you to refactor @mologie's code into: Template["login"].events({
"change input[name=username]": function () {
AutoForm.removeStickyValidationError('loginForm', 'username')
},
"change input[name=password]": function () {
AutoForm.removeStickyValidationError('loginForm', 'password')
}
}); |
Hello,
the documentation for sticky form errors states that
This does not seem to be working correctly. The form is never submitted while there are sticky validation errors, though the documentation implies that sticky errors should not prevent form submission. I am using AutoForm to model a login form as follows:
When hitting the login button, the debug console (Google Chrome) displays "AutoForm submit" once, and "AutoForm error" in all subsequent submission attempts.
Thanks,
Oliver
The text was updated successfully, but these errors were encountered: