-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat(mdMaxlength): support use with required and ng-trim #11136
Conversation
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
CLA consent here: #10083 (comment) |
I can't get the test to pass which is supposed to verify this functionality. In manual testing (demos), I can clearly see the functionality working as expected. But I can't get the required error to trigger in the test. |
3b2e11c
to
7dee818
Compare
The previous test issues have been resolved. Now the only failing tests have to do with AngularJS 1.5.x... |
7dee818
to
95c45c0
Compare
95c45c0
to
3b2a9cc
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.
LGTM
Thanks a ton @gkalpak! That's exactly the kind of feedback that I was looking for! I'll re-visit and make changes. |
👍 Feel free to ping me for another review 😃 |
Adding ng-trim="false" to an input will cause the 'required' state to be fulfilled by empty spaces, essentially allowing a user to put in no content and pass required validation. Allowing angular to trim, and trimming manually in the renderCharCount function works better (IMO).
3b2a9cc
to
2a48778
Compare
@gkalpak can you please take another look?
|
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.
A couple of nits.
LGTM otherwise 👍
src/components/input/input.js
Outdated
elementVal = ''; | ||
} | ||
elementVal = ngTrim && !isPasswordInput && angular.isString(elementVal) ? elementVal.trim() : elementVal; | ||
return String(elementVal).length === 0; |
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.
Nit: You can make a re-usable function for calculating the length of a value (which is used in the validator, $isEmpty()
and renderCharCount()
):
function caclulateLength(value) {
if (value == null) {
value = '';
} else {
value = ngTrim && !isPasswordInput && angular.isString(value) ? value.trim() : value;
}
return String(value).length;
}
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 had a feeling that this was needed. Thanks for confirming it. Much cleaner 😃
src/components/input/input.spec.js
Outdated
expect(pageScope.form.foo.$error['md-maxlength']).toBeFalsy(); | ||
}); | ||
|
||
it('should not trim spaces for required password inputs by default', 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.
Nit: This is not just "by default". It is the only posible behavior (i.e. it is not possible to override it).
src/components/input/input.spec.js
Outdated
|
||
pageScope.$apply('foo = " "'); | ||
expect(pageScope.form.foo.$error['required']).toBeFalsy(); | ||
}); |
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.
OOC, why not verify pageScope.form.foo.$error['md-maxlength']
too? (Possibly using foo = " "
as well to make it truthy.)
no longer force ng-trim="false" trim the value by default or based on the ng-trim attribute don't trim password inputs to align with AngularJS behavior Fixes angular#10082
2a48778
to
147551d
Compare
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) |
Setting CLA as yes after confirming both listed PR authors have signed CLA. |
PR Checklist
Please check that your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
When
md-maxlength
is used on aninput
that has therequired
attribute set, the required validation will accept blank spaces in the input as valid by default. Trying to override this withng-trim="true"
is ignored.Issue Number:
Fixes #10082
Fixes #10216
Relates to #5321
What is the new behavior?
By default, blank spaces in required inputs cause an invalid state. If this is undesirable, it can be overridden by adding
ng-trim="false"
to the input.Does this PR introduce a breaking change?
Other information
This is based on an abandoned PR (#10083).