-
Notifications
You must be signed in to change notification settings - Fork 176
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
Support validation group #175
Conversation
messageElem = angular.element(element[0].querySelector('#contact > p')); | ||
expect(messageElem.hasClass('validation-invalid')).toBe(true); | ||
}); | ||
}); |
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.
@lvarayut Do you want to create a new validationGroupSpec.js
for this test?
Since we have too many test cases in this file.
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.
That's what I was thinking at the first time. However, I decided to put it in the same file because the validation-group
is in the directive file. I'm afraid that we would get confused afterward. What do you think?
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.
Me too, I'm thinking about the same thing before. As you can see the current folder of the test, I have combined all the directive spec in different files.
I agree with you that we may get confused afterward, but without making it clear, the test file will harder to modify and fix.
I suggest we create a new test file if given a new test case, for the previous old one we can keep them originally until we enhance them and move them to the new file.
What do you see?
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.
You're right. Let's do it!
Is this possible to validate group? for example we validate the Form using $validationProvider.validate(Form); validate single input $validationProvider.validate(Form.required); I wish we can have the opportunity to validate group $validationProvider.validate(checkboxGroup); |
For every validation-group, there is only one output message, am I right? |
@@ -379,7 +379,7 @@ | |||
var validCallback = $parse('success'); | |||
var messageElem; | |||
|
|||
if (attrs.messageId) messageElem = angular.element(document.querySelector('#' + attrs.messageId)); | |||
if (attrs.messageId || attrs.validationGroup) messageElem = angular.element(document.querySelector('#' + (attrs.messageId || attrs.validationGroup))); |
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.
What about define
var validationGroup = attrs.validationGroup
so that we use validationGroup instead of repeatly calling attrs.validationGroup within the function.
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.
That's a great advice! Same for attrs.messageId
. I'll fix both of them.
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.
Thank you. Same for other attributes :)
I haven't tested it but it should work in both of them because, in the code, I just verified that in case of any elements of the group error, it will show an error message. Otherwise, it'll be valid. All the "
I'll take a look at this case. |
Ok, I will test that too :) |
expect(messageElem.hasClass('validation-invalid')).toBe(true); | ||
}); | ||
}); | ||
}); |
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.
Thanks @lvarayut
@lvarayut I have gone through your code so this attribute different Form: <form name="Form1"></form>
<form name="Form2"></form> We should clarify this condition in the API document, because the term "group" is easily misunderstood. |
Ok. I'll say it in the |
There are two more things to do
Thank you @lvarayut after these ready to merge 😄 🍻 |
Thanks @huei90 for your great review. I'll do as your suggestions and also the following:
|
Thank you @lvarayut @Nazanin1369 Tests are now more important as our project is getting bigger and having a lot of features, so we should take the test cases very seriously and carefully in our future commit. ☀️ |
- Add the note in order to clearly state that the validation-group can only be used for elements placed in the same form tag
Seems everything is ready, I'm going to merge it. 👍 @lvarayut |
Thanks @huei :) On Sunday, December 27, 2015, Huei Tan [email protected] wrote:
|
Hi, am I missing something here? All this does is hide the error message but the form is still invalid? checkValid does not take validation groups into account, so how can this work? You can see this on the demo page with the 2 check boxes. Or is this intended behaviour? |
Also, this should only be targeting the required expression. eg, If a form field is an email, it makes no sense to allow the user to submit whatever they want just because another element in the group is valid? |
@juw177 Well. It depends on the logic of your application. If you need only one field to be filled out by a user, as shown in the example, it totally makes sense and it's the purpose of using
It didn't hide any error message. If one of the elements is valid, the entire form is still valid. |
@lvarayut Thanks for that explanation. However, I am not seeing this behaviour of the entire form being valid when I go to the example page here: http://huei90.github.io/angular-validation/#examples If you go to the form with Checkbox 1 and Checkbox 2, both with |
You're right. Thanks for reporting. I'm working on it. @juw177, if you could come up with any good idea to handle it, please let me know. Or if you could send a PR, that would be really welcomed. |
PRs are always welcomed. 🙏 |
I added a
validation-group
attribute that could be used to group many elements into a group. The group will be considered as valid if and only if one of them is valid. Otherwise, the group will be marked as invalid. A valid/invalid message will be placed inside an element that contains an id attribute with the same name as provided to the directivevalidation-group
.Closed #40