Gbuomprisco / ngx-chips

Tag Input component for Angular
MIT License
902 stars 359 forks source link

Failed validation clears formValue #860

Open lagopus1990 opened 5 years ago

lagopus1990 commented 5 years ago

PLEASE MAKE SURE THAT:

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

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

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

Current behavior

When validation fails the input field is always cleared. This is undesirable if the validation failed by a typo of a user, resulting in the user to have re-type the complete input again.

Expected behavior

An option to keep the input value when validation fails.

I have implemented this behaviour for myself, but as I am very new to Angular, I am not confident to ask for a pull request, but so for now, I good to go.

Minimal reproduction of the problem with instructions (if applicable)

<tag-input [(ngModel)]='email_to' [trimTags]="true" [separatorKeyCodes]="[13, 188, 186]" [addOnBlur]="true" [ripple]="false" [modelAsStrings] = "true" [validators]="validators"> </ tag-input>

validators = [Validators.required, Validators.pattern('^\w+([\.-]?\w+)@\w+([\.-]?\w+)(\.\w{2,3})+$')];

What do you use to build your app?. Please specify the version

angular-cli 6.0.8

Angular version:

6.0.4

ngx-chips version:

2.0.0-beta.0

Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

all

g3344 commented 5 years ago

I agree. It would be great to keep the value when the validation error fails

hupptechnologies commented 5 years ago

This line clears value on submit then it fires validation. So i guess you can do chages in module and publish own npm plugin. I did same but i have so many changes also that will not meet your requirements so better you do it for your own.

barsurfer commented 5 years ago

@lagopus1990 @hupptechnologies can you please share the workaround for that issue?