md-autocomplete not ng-required compatible
When using ng-required with an md-autocomplete it creates a normal input that has a fixed required="required" attribute. So conditionally setting the required attribute is not possible.
+1
Oh please +1! This is blocking me so bad!
+1
It seems like the functionality is already supposed to exist, maybe:
https://github.com/angular/material/blob/v1.0.0-rc2/src/components/autocomplete/js/autocompleteController.js#L158
Then in the directive template, isRequired is used for an internal ng-required. This all appears to make sense.
But I'm experiencing the same thing; although ng-required correctly sets or removes "required" from the actual md-autocomplete element, the change isn't propagated to the inner input. Is there something wrong with that observe check? Should that be undefined instead of null...? (I never used observe, so I don't know what the new value becomes when an attribute is removed, but that would have been my guess.)
@bathos @robertmesserle Changing that line to use !!value works as it was originally intended(treating null/undefined as false).
Make
$attrs.$observe('required', function (value) { ctrl.isRequired = value !== null; });
Become
$attrs.$observe('required', function (value) { ctrl.isRequired = !!value; });
Here are some of examples of the logic output before/after
Using value !== null
true !== null
true
false !== null
true
undefined !== null
true
Using !!value
!!true
true
!!false
false
!!undefined
false
!!null
false
@robertmesserle Thanks! I was going to do a pr but I got caught up trying to get a test to work.
Is there any way to have gulp karma(or similar) stop when it encounters an error? Or at least list all errors at the end? I believe this is how it used to work a few months ago but it looks like things changed a bit.
@epelc Hm, I'm not sure. I know I've definitely wanted this functionality, but haven't devoted the time to figuring it out. =p