I want to add new input field on click but to select the text on the previous input field so that it will be edited.
When I click on field (Add Workstation) I want to select the previous field with (Unnamed workstation) and the Add workstation to be always visible and below. I have been trying to find a way to achieve this but with no luck until now.
html:
<div class="_form-item" *ngIf="item.type=='station'&& item.id" style="padding-top: 32px">
<div class="_label">Work Stations</div>
<div class="_ml-12 _pt-8 _flex-row" *ngFor="let work_station of item.children; let i = index;
trackBy: customTrackBy">
<input [id]="i" (ngModelChange)="updateWorkStation(i)"
[(ngModel)]="item.children[i].name"
type="text"/>
<div class="_icon-button" (click)="removeWorkStation(i)"><i
class="material-icons md-dark md-18">clear</i>
</div>
</div>
<div class="_ml-12 _pt-8 _flex-row">
<input (click)="createWorkStation()" placeholder="Add work station" [(ngModel)]="newWorkStation"
type="text"/>
<!--div class="_link-button">Add</div-->
</div>
</div>
component function:
createWorkStation() {
let item = new Location();
item.type = 'work_station';
item.name = 'Unnamed work station ';
item.parent = this.item.group_id;
this.service.create(item)
.map((response: Response) => <Location>response.json())
.takeWhile(() => this.alive)
.subscribe(
data => {
this.onCreateChild.emit({id: data.id});
},
err => {
console.log(err);
}
);
}
item.childrenyou display increateWorkStation. The View will update itself.