material icon indicating copy to clipboard operation
material copied to clipboard

md-autocomplete not ng-required compatible

Open visurel opened this issue 11 years ago • 7 comments

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.

visurel avatar Oct 03 '15 20:10 visurel

+1

tinusn avatar Oct 07 '15 08:10 tinusn

Oh please +1! This is blocking me so bad!

bvilches avatar Oct 15 '15 14:10 bvilches

+1

Pelu2k12 avatar Oct 22 '15 17:10 Pelu2k12

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 avatar Oct 30 '15 12:10 bathos

@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

epelc avatar Nov 18 '15 19:11 epelc

@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 avatar Nov 18 '15 19:11 epelc

@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

robertmesserle avatar Nov 18 '15 19:11 robertmesserle