vladotesanovic / ngSemantic

Angular 2 building blocks :package: based on Semantic UI
https://ng-semantic.herokuapp.com/
MIT License
973 stars 148 forks source link

sm-select not working for formArray #168

Closed mkndn closed 7 years ago

mkndn commented 7 years ago

I have the following html script

<form [formGroup]="testForm" novalidate (ngSubmit)="save(testForm.value)">
<div fomArrayName="testAttributes">
<div [formGroupName]="0">
<sm-select
    [options]="{direction: 'downward'}" 
    placeholder="Attributes" 
    [formControl]="attributeMaster"
    (onChange)="updateModel($event);"
    class="fluid">
    <option *ngFor="let item of selectAttributes" [value]="item.label">
        <span [innerHTML]="item.value.displayName"></span>
</sm-select>
</div>
</div>
</form>

And in my component

public buildForm(): void {
    this.testForm = this._fb.group({
        testAttributes: this._fb.array([])
    });
    this.loadFormArray();
}

public loadFormArray(): void {
    this.attributesFromServer.forEach(attribute => {
        (<FormArray>this.testForm.controls["testAttributes"]).push(this.createArrayData(attribute))
    })
}

public createArrayData(attribute: Attribute) {
    return this._fb.group({
        attributeMaster: [attribute.attributeMaster, <any>Validators.required]
    })
}

When i run the application, i am getting the following error,

Cannot find control with unspecified name attribute

When i change the html script to

<sm-select
    [options]="{direction: 'downward'}" 
    placeholder="Attributes" 
        formControlName="attributeMaster"
    (onChange)="updateModel($event);"
    class="fluid">
    <option *ngFor="let item of selectAttributes" [value]="item.label">
        <span [innerHTML]="item.value.displayName"></span>
</sm-select>

Iam getting the following error,

No value accessor for form control with path: 'testAttributes -> 0 -> attributeMaster

And the error point to the line where we set the formControl attribute for sm-select above. Please help.

mkndn commented 7 years ago

I got it working. My bad i didn't notice the [control] attribute for sm-select in the demo page before. My Apologies. I changed [formControl] to [control] and it's working now.