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.
Can you comment on why this feature is deprecated? Is so what is the correct way to handle required with the chips directive.
This issue is closed as part of our deprecation effort.
For details, see our post Spring Cleaning 2016.
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.
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.
There is a md-max-chips, but no md-min-chips, and required is not worked with md-chips.
Does this mean there is no planning to make required validation work at all?
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
Is there a way to make "$pristine, $touched" work on chips?
Work around:
Custom form validation, which you can update in the controller using the md-on-add
& md-on-remove
md-chips callbacks functionality.
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.
Most helpful comment
There is a md-max-chips, but no md-min-chips, and required is not worked with md-chips.