-
-
Notifications
You must be signed in to change notification settings - Fork 128
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
Validation rules per field do not appear to be independent resulting in misleading UI feedback #438
Comments
When I came up with the requirements for validation I intended there be two concepts of So this would call the server once if email is valid and username is invalid:
and this would call the server twice, but only if both email and username are valid
I'd also like to see an optional parameter |
To extend on your examples, lets say we have this:
If email is valid and present, then myEmailRule will run regardless of the status of the username field. Likewise if username is present and satisfies the length requirements, then myUsernameRule will run regardless of the status of the email field. Only when they have both satisfied all rules (including myEmailRule and myUsernameRule) will emailNotAlreadyRegistered and usernameNotInUse be called. Am I understanding what you're saying correctly? |
Yes, that's what I'm suggesting. |
See also #279 and #424. Fine-grained control over rule execution sequence is hard to get with the fluent API. Some other solutions that will work right now:
A more comprehensive solution would be ideal, but I'm not sure what that should look like. |
Does this work for you: ValidationRules
.ensure('email')
.email()
.required()
.ensure('username')
.required()
.minLength(3)
.maxLength(50)
.then()
.ensure('email')
.satisfiesRule('emailNotAlreadyRegistered')
.ensure('username')
.satisfiesRule('usernameNotInUse'); |
I'm not keen on this syntax for the concept of We don't need to implement everything nicely in the syntax, but we do need to try and avoid a situation where something is almost impossible. The above example (and current syntax) doesn't allow nesting of rules. Simple nesting support might allow 'groups' of validation, each implementing the same 'rule' interface, so any combination of rules could be applied. Since each 'group' was a 'rule' it would also provide messages such as "The address is invalid" if any of the child properties was in error. What if we have a 'fullname' rule that requires firstname and lastname be valid? As a thought-provoker:
I think this would address the sequential handling issues, and I suppose the default or 'implied' handling is parallel, although I'd prefer to see an explicit grouping of the parallel to remove visual ambiguity, perhaps with a |
I meant does #438 (comment) solve the issue using the current release? |
I thought it did at first, but we switched over to using bindings vs objects at some point so I think that's why it seems like it works. I swapped back to what I had put in the original question (without object validation) and that also behaved as I expected. I had to swap over to bindings vs objects because it seemed like the objects just randomly wouldn't be there, no idea why. I still have a screen that is doing objects, I will put something together and try it out. I also owe you a gist for the components and validation. |
I'm submitting a bug report
Please tell us about your environment:
Operating System:
Windows 10
Node Version:
v6.9.1
NPM Version:
3.10.9
JSPM OR Webpack AND Version
webpack 2.3.3
Browser:
all
Language:
ESNext
Current behavior:
Validation when using a ValidationRules object doesn't behave as I'd expect. Given this example from the doc hub
validation will run in two sequences when validate() is called. First to evaluate both email and username up to the then() statements, and then email and username for the two satisfiesRules. If username isn't present, and email() and required() are valid on email, emailNotAlreadyRegisterd is not evaluated.
Expected/desired behavior:
I would expect each "ensure" to be handled independently, with two sets of sequence arrays per ensured attribute. As an example, email would have a sequence[0] of email, required, and a sequence[1] of satisfilesRule('emailNotAlreadyRegistered')
username would have a separate sequence set, sequence[0] of required, minlength, maxlength, and sequence[1] of satisfiesRule('usernameNotInUse');
Even if username is not completely evaluated, email should be validated as completely as possible.
What is the motivation / use case for changing the behavior?
If the top level validation (sequence[0]) failed for field1 and succeeds for field2, but the second level of validation (sequence[1]) would fail for field2, the user isn't alerted to the failure until they fix the failure with field1, even though they don't have any reason to be linked. This is a poor user experience.
The text was updated successfully, but these errors were encountered: