I have created a form in my application.
mapForm = this.fb.group({
name: ['', Validators.required],
view: this.fb.group({
width: ['', Validators.required],
height: ['', Validators.required]
})
});
In this form, I am creating a JSON like following:
{
name: "x",
view:{
width: "100%",
height: "100%"
}
}
So my form is:
<form [formGroup]="myForm" (ngSubmit)="onSubmit()">
<label>
First Name:
<input type="text" formControlName="firstName" required>
</label>
<div formGroupName="view">
<h3>View</h3>
<label>
width:
<input type="text" formControlName="width">
</label>
<label>
height:
<input type="text" formControlName="height">
</label>
</div>
</form>
But I want to seperate my view's width/height value (100) and unit (%) properties two input elements and join them in json.
<label>
width:
<input type="text" formControlName="height" value="100">
</label>
<label>
unit:
<input type="text" formControlName="unit" value="%">
</label>
But my view.width will be "100%". How can I do it?