ngx-chips icon indicating copy to clipboard operation
ngx-chips copied to clipboard

Broken Validation when using Angular validators

Open aronmgv opened this issue 6 years ago • 1 comments

Hi,

As stated in docs this apparently supports native angular validators.. but what I am supposed to define as a FormControl type

  • Primitive - FormControl
  • Array - FormArray
  • Group - FormGroup

In order to get proper input validation?? Your component apparently can only be bound with formControlName just with FormControl. However it actually generates an array of primitives (when modelAsStrings is set to true) so the validation itself is broken since it expects primitive type like string not an array.. so my form stays INVALID.. I expected full compatibility with reactive-forms since you claim support with angular validators.. So in order to get form validation to work properly you need to implement support with FormArray as a control for the input since it natively creates an array..

Or maybe I am missing something.. but dont think so, since when I updated using (onAdd) control value ['1.1.1.1'] to '1.1.1.1' the validation started to work..

This is reproduction when modelAsStrings is set to true for simplification. But needs to be fixed also when objects are present in the input, so the validators are checking against value property of objects inside the array..

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] support request/question

Notice: feature requests will be ignored, submit a PR if you'd like

Current behavior Broken validation, see above.

Expected behavior Proper validation taking advantage of native angular validators for the reactive forms.

Minimal reproduction of the problem with instructions (if applicable) Just add some pattern validators for the input and form will stay invalid since it expects plain value not an array of values.. validation is thus broken

What do you use to build your app?. Please specify the version angular-cli: 7.1.1

Angular version: 7.1.0

ngx-chips version: 2.0.0-beta.0

Browser: [all]

aronmgv avatar Jul 09 '19 10:07 aronmgv

Can you provide a reproduction? Last time I checked the validation worked correctly using the demos

Gbuomprisco avatar Aug 08 '19 21:08 Gbuomprisco