-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Conversation
@@ -727,6 +727,9 @@ describe('input', function() { | |||
it('should invalid shorter than given minlength', function() { | |||
compileInput('<input type="text" ng-model="value" ng-minlength="3" />'); | |||
|
|||
changeInputValueTo(''); | |||
expect(scope.value).toBeUndefined(); |
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.
This is the failing assertion
HTML5 doesn't really have a proper minlength attribute, but emulating it with the pattern attribute, if an input isn't required, then the empty string appears to be perfectly valid in spite of not matching the pattern. http://jsfiddle.net/2g2ce/1/ Perhaps this is also appropriate for angular, but I'm not sure. |
Is it correct to say that an empty string should always be valid, unless the input is has the It's a strange edge case, but I guess matching HTML5 makes the most sense. |
@bwiklund I think that sounds right. think about the end-user and developer experience: if an optional form field should contain at least 3 chars, then we can't make the field invalid if it's empty, because otherwise the user would always have to fill it with at least 3 chars and it would not be optional any more. |
since this behavior is a bit surprising we should have an explicit |
@caitp 👍 for the example! |
@bwiklund btw when I asked you for a test in #5643 I meant a test that will check that we allow min and max length to be updated via databinding at runtime and the that the next time the input change we use the new min/max values are used for validation. we need one spec ( |
Sounds good, I'll get that together tomorrow. |
Is this the behavior we're trying to test for? Because databinding on minlength/maxlength doesn't seem supported at the moment. |
Both cases - valid when value becomes empty and dynamically evaluated attributes - are available since 1.3.0-beta.12 (valid when empty possibly earlier) |
Are these assertions correct? I'm adding new tests to minlength/maxlength, and the minlength one is failing. Should it be failing?