-
Notifications
You must be signed in to change notification settings - Fork 43
pat-validation: Added the possibility to check for fields equality #740
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
Conversation
|
Very useful! |
This is particularly interesting for password or email confirmation fields
95ef6aa to
ec5c5a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor changes requested..., otherwise LGTM
| | Property | Description | Default | Type | | ||
| |-------------------|------------------------------------------------------------------------------------|---------|------| | ||
| | disable-selector | A selector for elements that should be disabled when there are errors in the form. | | CSS Selector | | ||
| | equality | Field-specific. The name of another input this input should equal to (useful for password confirmation). | | String | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add an entry for message-equality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
| this.$el.find("[name=" + opts.equality + "]").each( | ||
| function (idx, el) { | ||
| if (input.value !== el.value) { | ||
| constraint.equality = {'attribute': opts.equality, 'message': '^'+opts.message["equality"]}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding of http://validatejs.org/#validators-equality the attribute attribute shouldn't be neccessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what the '^ is for? it looks strange, but I see all the other message-* attributes have it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding of http://validatejs.org/#validators-equality the
attributeattribute shouldn't be neccessary.
If I remove it the tests fail. I think attribute is mandatory when you also specify a message.
Do you know what the '^ is for? it looks strange, but I see all the other message-* attributes have it too.
No idea, I put it there to be consistent with the already existent code :)
src/pat/validation/validation.js
Outdated
| } | ||
|
|
||
| // Handle fields equality | ||
| if (opts.equality && input.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the && input.value check should be removed. You probably still want to check for equality if no value was given. Instead of checking for && input.value we can enforce presence via the required attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the check
|
I implemented all the requested changes except #740 (comment) because either I did not understand how to do it or it is not possible to omit the |
This is particularly interesting for password or email confirmation fields