-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(autocomplete, select, virtualrepeat, input): correctly validate attribute values #6803
fix(autocomplete, select, virtualrepeat, input): correctly validate attribute values #6803
Conversation
763adf6
to
e6c68b4
Compare
@@ -163,8 +163,8 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming, | |||
*/ | |||
function configureWatchers () { | |||
var wait = parseInt($scope.delay, 10) || 0; | |||
$attrs.$observe('disabled', function (value) { ctrl.isDisabled = !!value; }); | |||
$attrs.$observe('required', function (value) { ctrl.isRequired = !!value; }); | |||
$attrs.$observe('disabled', function (value) { ctrl.isDisabled = value !== 'false'; }); |
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.
Could the value not interpolate to '0' also ? This solutions seems limited.
e6c68b4
to
5cb2785
Compare
@ThomasBurleson - It now supports interpolated |
5cb2785
to
ab5f6c4
Compare
required
and disabled
attribute
-- Now fixing #6698 too, after merging my old PR into this by using the new util method. |
* @param value Interpolated Attribute Value | ||
* @returns {boolean} | ||
*/ | ||
parseAttributeBoolean: function(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.
@jelbourn - I think we should regex match on the value
string. Thoughts or code suggestions ?
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.
Won't do a negated match for /(false|0)/g
?
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 wouldn't consider the "zero" string to be falsy. Without that the check is fine as-is.
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.
@devversion Can you remove the check for '0' and update the PR? Other than that, it looks good to me.
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.
@robertmesserle - Yes will do, just thought I need that because Thomas asked about the interpolated zero
as a falsy value.
ab5f6c4
to
6721dbf
Compare
@ThomasBurleson @robertmesserle @jelbourn - Okay removed the |
Just to clarify, the use-case would be something like:
Is that right? I don't have a strong opinion one way or the other, I'll defer to @ThomasBurleson and @jelbourn for this. |
Okay, just wan't to answer your question 😄 .
|
6721dbf
to
38b20f3
Compare
38b20f3
to
d86f34a
Compare
d86f34a
to
5688de2
Compare
@ThomasBurleson At the moment in this PR, in most cases we support The users should better use
Just tell me, then I will remove the new checks for these types. But please think about the issues too (#5896, #6415) |
While treating these as boolean attributes is correct, it would be a breaking API change. |
@jelbourn Sorry, I didn't get it. Should we continue this.. or should I remove that? Edit: Ah, you answered to @robertmesserle's message. |
3c4d106
to
5412559
Compare
5412559
to
4b4a226
Compare
@jelbourn according what I've read this PR doesn't seems like a breaking API, it just enables wider range of values, more than that the old behavior won't break. |
@EladBezalel We would be changing the behavior of, for example, |
@jelbourn I've changed that a few days ago, it's currently only a issue of the autocomplete directive ( BTW: |
4b4a226
to
29ad320
Compare
…e values as boolean Fixes angular#5831 Fixes angular#7063 Fixes angular#6415 Fixes angular#6393 Fixes angular#5896 Fixes angular#6698 Fixes angular#7105
29ad320
to
71cd708
Compare
@devversion May I suggest to add |
@wembernard I would like to have this PR merge, before looking at the actual BTW: As discussed with @jelbourn I removed the breaking attribute changes. PTAL |
Will this PR fix the issue with multiple="false"? If yes, I vote +1 UPDATE I found the solution for multiple="false", we should bind using ng-multiple. As @rschmukler mentioned at #5459 |
@leocaseiro Yes, that will be a good workaround for that, and yes this PR adds a basic boolean validation for |
how about ng-required, ng-multiple, ng-disabled and ng-readonly? |
@leocaseiro Yes exactly that's the right usage for these attributes. By default |
Fixes the validation of the boolean attributes.
Autocomplete
Attributes:
required
ignored an empty attribute value (<md-autocomplete required>
)disabled
ignored an empty attribute value (<md-autocomplete disabled>
)Input
Attributes:
Extra Changes:
required
is not updating themd-required
class (now observing forng-required
)md-no-asterisk
Select
Attributes:
Virtual Repeat
Attributes
Extra Changes:
md-on-demand
Notes
negative
attribute values forrequired
,readonly
,disabled
will be ignored.0
as falsy value is also a useful feature and should be implemented too, because sometimes your backend will return aboolean
in numeric style (See here).Fixes #5831 Fixes #7063 Fixes #6415 Fixes #6393 Fixes #5896 Fixes #6698 Fixes #7105