material icon indicating copy to clipboard operation
material copied to clipboard

mdChips: required validator isn't run on model change

Open Emeegeemee opened this issue 10 years ago • 10 comments

Demo showing required isn't working properly when removing all of the chips.

Expected behavior: ng-message for the required validator should be displayed saying 'At least one chip is required.' It should behave similarly to md-max-chips which can be shown by adding 5 chips.

Current behavior: no message is shown.

Emeegeemee avatar Apr 20 '16 02:04 Emeegeemee

Can you comment on why this feature is deprecated? Is so what is the correct way to handle required with the chips directive.

Emeegeemee avatar Apr 21 '16 17:04 Emeegeemee

This issue is closed as part of our deprecation effort. For details, see our post Spring Cleaning 2016.

ThomasBurleson avatar Apr 28 '16 19:04 ThomasBurleson

The chips model is a list that is mutated in place; It doesn't "change". You need to set up a $watchCollection on the model to track insertion/removal.

vbraun avatar May 03 '16 14:05 vbraun

I am aware that the array reference doesn't change. However, your solution to use $watchCollection comes with a performance cost of running every digest cycle that is unnecessary if the validators are run in the mdChips directive per my pull request above. Besides with the addition of the md-max-chips validator, it shows users clearly want validators on the content of the array not the reference to the array.

I don't even need the NgModelController.$isEmpty override just calling the NgModelController.$validate method on content change would allow me to create any validators that I would need.

Emeegeemee avatar May 03 '16 15:05 Emeegeemee

There is a md-max-chips, but no md-min-chips, and required is not worked with md-chips.

hantsy avatar Nov 18 '16 08:11 hantsy

Does this mean there is no planning to make required validation work at all?

dephiros avatar Nov 30 '16 00:11 dephiros

Thanks for contributing with the PR. Too bad the spring cleaning was that thorough.

We also needed some 'normal' validation for the chips. Here's a decorated version of the mdChipsDirective with expected min and max validation.

Example: https://codepen.io/jakobadam/pen/PpwKmz

kind regards, Jakob

jakobadam avatar Apr 20 '17 14:04 jakobadam

Is there a way to make "$pristine, $touched" work on chips?

Deimos620 avatar Jan 15 '18 02:01 Deimos620

Work around:

Custom form validation, which you can update in the controller using the md-on-add & md-on-remove md-chips callbacks functionality.

amass01 avatar Feb 16 '18 10:02 amass01

I try to continue on this problem, maybe also adding md-min-chips later. But first start with required. We'll see how this will end up ;) I have a good feeling.

fsmeier avatar Feb 16 '18 16:02 fsmeier