I'm making a dynamic form. A Field
has a list of values. Each value is represented by a string.
export class Field{
name: string;
values: string[] = [];
fieldType: string;
constructor(fieldType: string) {this.fieldType = fieldType;}
}
I have a function in my component which adds a new value to the field.
addValue(field){
field.values.push("");
}
The values and the button are displayed like this in my HTML.
<div id="dropdown-values" *ngFor="let value of field.values; let j=index">
<input type="text" class="form-control" [(ngModel)]="field.values[j]" [name]="'value' + j + '.' + i"/><br/>
</div>
<div class="text-center">
<a href="javascript:void(0);" (click)="addValue(field)"><i class="fa fa-plus-circle" aria-hidden="true"></i></a>
</div>
As soon as I write some text in an input of a value, the input loses focus. If I add many values to a field and I write a character in one the values input, the input lose focus and the character is written in every input.