I'm trying to create dynamic fields using this code
formInputfieldsForm: FormGroup[];
defaultFields: any = [
{ inputType: 'textbox', inputValues: '' },
{ inputType: 'textbox', inputValues: '' },
]
createForm(a?: any, b?: any, c?: any): FormGroup {
return this.formService.group({
"inputType": [b, Validators.required],
"inputValues": [c, Validators.required],
})
}
addFields(){
this.defaultFields.forEach((ele, i) => {
this.formInputfieldsForm.push(this.createForm(ele?.inputType, ele?.inputValues));
});
}
createFieldsForm(): FormGroup {
return this.formService.group({
"inputType": [null, Validators.required],
"inputValues": [null, Validators.required],
})
}
addFields(){
this.formInputfieldsForm.push(this.createFieldsForm());
}
every time addFields is called new dynamic fields are created
in frontend i'm using loop to render elements like this
<div *ngFor="let expForm of formInputfieldsForm; let i = index;" [formGroup]="expForm">
<select class="hand_symbol" formControlName="inputType" placeholder="Select Input Type">
<option value="">Select</option>
<option value="textbox">Textbox</option>
<option value="dropdown">Drop Down</option>
<option value="textarea">Textarea</option>
</select>
<input class="form-control" formControlName="inputValues" type="text" placeholder="Enter Values" type="text">
</div>
<span title="Add" (click)="addFields()">add</span>
it is rendered now i need by default inputValues control should be disabled and if i select dropdown from select control then only it should be enabled
any solution Thanks
addFieldsmethod and if i select dropdown then it should be enabled