-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,8 +26,11 @@ define([ | |
| parser.addArgument("message-min", "This value must be greater than or equal to %{count}"); | ||
| parser.addArgument("message-number", "This value must be a number"); | ||
| parser.addArgument("message-required", "This field is required"); | ||
| parser.addArgument("message-equality", "is not equal to %{attribute}"); | ||
| parser.addArgument("message-confirm", "This field is required"); | ||
| parser.addArgument("not-after"); | ||
| parser.addArgument("not-before"); | ||
| parser.addArgument("equality"); | ||
| parser.addArgument("type", undefined, ["integer", "date", "datetime"]); | ||
| var VALIDATION_TYPE_MAP = { | ||
| 'required': 'presence', | ||
|
|
@@ -163,6 +166,18 @@ define([ | |
| constraint.numericality.onlyInteger = true; | ||
| } | ||
| } | ||
|
|
||
| // Handle fields equality | ||
| if (opts.equality) { | ||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more. In my understanding of http://validatejs.org/#validators-equality the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If I remove it the tests fail. I think
No idea, I put it there to be consistent with the already existent code :) |
||
| } | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| // Set local validation messages. | ||
| _.each(Object.keys(VALIDATION_TYPE_MAP), function (type) { | ||
| var c = constraints[name][VALIDATION_TYPE_MAP[type]]; | ||
|
|
||
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!