-
-
Notifications
You must be signed in to change notification settings - Fork 902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error "Multiple select model should be array" in NgForm #348
Comments
@Maxkorz there is validation error since you are binding same property |
@varnastadeus Sorry but you are wrong. Each dropdown is unique as it is bound to local I made three different dropdowns to show the error in different scenarios. If you want, here's a single dropdown https://stackblitz.com/edit/angular-tr8vjg?file=app/app.component.css I'm still getting the error. |
@Maxkorz sorry I overlooked that. Error is happening because |
@varnastadeus but Also, the error happens when initial value is private _validateWriteValue(value: any) {
if (!isDefined(value)) {
return;
} |
@Maxkorz it doesn't happens when it's null. Firstly when form is created initial value of city is |
It does happen for me. Take a look at this demo https://stackblitz.com/edit/angular-fcpv2n?file=app/app.component.ts
I'm using a basic feature of Angular. I'm pretty sure the issue is somewhere in your plugin. I'm using over 20 3rd party modules in my project and only this plugin has such issue. |
It doesn't comes out of nowhere, it comes from form you are having. |
You were right. That's how Angular works. Maybe you could extend "isDefined" method to filter out empty strings? |
Simply workaround would for now would be to initial ngModel with empty array like this But this is a bug, ngModel should not need to be set at all if it is used only for form to gather values. I will fix it. |
* fix: skip writeValue handling if value is empty fixes ng-select#348 * warn if ngModel is not valid and skip
How the error can be resolved? |
If you still have an error, check the form control initial value when creating the group. Example: this.fb.group({someValue: new FomControl({value: []})}) -> this should be this.fb.group({someValue: new FomControl([])}), as this syntax with ({value: []}) can introduce this issue. |
Expected behaviour
Error
Error: Multiple select model should be array.
should not happen when<ng-select>
is being used insideNgForm
.Actual behaviour
The error happens when ngModel is
null
and when ngModel is a predefined array.Demo: https://stackblitz.com/edit/angular-jtj3dd?file=app%2Fapp.component.html
More Info
ng-select version: 0.26.1
browser: Google Chrome
reproducible in demo page: NO (demo doesn't have NgForm example)
The text was updated successfully, but these errors were encountered: