ng2-select icon indicating copy to clipboard operation
ng2-select copied to clipboard

If ngModel is used within a form tag, either the name attribute must be set or the form

Open halukkaramete opened this issue 8 years ago • 2 comments

got this on my html

<ng-select  name = "topicUI" 
                            [(ngModel)]="topicsChosen"   
                            [multiple]="true"
                            [items]="items"
                            [disabled]="disabled"
                            (data)="refreshValue($event)"
                            (selected)="selected($event)"
                            (removed)="removed($event)"
                            placeholder="No city selected"></ng-select>

but yet, I'm still getting this error:

ManageLearningPlanComponent.html:458 ERROR Error: 
If ngModel is used within a form tag, 
either the name attribute must be set or the form
control must be defined as 'standalone' in ngModelOptions.

      Example 1: <input [(ngModel)]="person.firstName" name="first">
      Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">
    at Function.webpackJsonp.../../../forms/@angular/forms.es5.js.TemplateDrivenErrors.missingNameException (forms.es5.js:4040)

What am I doing wrong here? ( The only thing I did not do in the instructions is to include ng2-select.css )

halukkaramete avatar Dec 02 '17 03:12 halukkaramete

I've figured what was wrong. I was missing the name attribute of the button too. name="myNameIsTrinity" did the trick.

<button name="myNameIsTrinity" type="button" class="btn btn-primary" [(ngModel)]="disabledV" btnCheckbox btnCheckboxTrue="1" btnCheckboxFalse="0"> {{disabled === '1' ? 'Enable' : 'Disable'}}

Why don't you update your demo to throw in the names to avoid this?

halukkaramete avatar Dec 02 '17 11:12 halukkaramete

Had the same issue, I put the name attribute to ng-select like this:

<ng-select name="anyName" ... ></ng-select>

MichalJakubeczy avatar Mar 13 '19 15:03 MichalJakubeczy