In my application, the input fields are populated dynamically based on the API response. Each field has a corresponding set of buttons associated with it, which I only want to show when the field is edited.
Here is an image of the form:
https://i.sstatic.net/8opQq.png
I am currently using simple ngModel for viewing and changing the values. Since the fields do not have complex validations, I am not interested in using a reactive form approach. My requirement is that when a user types into a field, the respective button set should appear. Upon clicking either button, the field should return to its original pristine state.
Below is the code snippet for populating the template:
<h5 class="mb-4">Report Configuration</h5>
<div class="form-group row" *ngFor="let config of reportConfig">
<label class="col-sm-12 col-md-4 col-form-label">{{config.title}} <span
class="text-danger">*</span></label>
<div class="col-sm-12 col-md-6 col-lg-6">
<input type="text" [class.is-invalid]="false" [id]="config.propertyKey" [(ngModel)]="config.propertyValue" class="form-control" />
<!-- On typing the field should be marked dirty & buttons should appear -->
</div>
<div class="col-sm-12 col-md-2 col-lg-2 pl-0">
<mat-icon class="mr-2" (click)="should mark the field pristine">check_small</mat-icon>
<mat-icon color="warn" (click)="should mark the field pristine">close_small</mat-icon>
</div>
</div>
Can this functionality be achieved using ngModel, or do I need to use FormArray to accomplish this?