x/4.x & bootstrap coders,
I used patchValue
to fill a control with data but this does not effect the dirty flag, leaving the form pristine. Should behave like this or is this a bug?
The control:
<div class="form-group has-feedback">
<label class="col-sm-2 control-label" for="projects">{{ 'projects' | translate }}*</label>
<div class="col-sm-10">
<input type="text" class="form-control" formControlName="projects" style="cursor: pointer" (click)="this.clickedShowProjectsForm()" aria-describedby="projects" placeholder="{{ 'choose a project' | translate }}">
<span class="glyphicon glyphicon-menu-right form-control-feedback" style="color: #007734!important" aria-hidden="true"></span>
</div>
</div>
The filling using patchValue:
this.formGroup.patchValue({
projectId: id,
projects: selectedProject
});
This was supposed to make my buttons react. But is does not... :-(
The buttons are defined as follows:
<div style="text-align:center">
<button class="btn btn-success button" (click)="clickedStore();" [disabled]="!(formGroup.valid && !formGroup.pristine)">{{ 'store' | translate }}</button>
<button class="btn btn-danger button" (click)="clickedCancel();" [disabled]="formGroup.pristine">{{ 'cancel' | translate }}</button>
</div>
I check stackoverflow and something was mentioned in:
How to programmatically change pristine property in angular 2 form without ng-model
There they manually alter the pristine flag, so I tried the same, using:
this.formGroup.controls.projects.value.markAsDirty();
It has no effect what so-ever...
So is this a bug or desired behavior?
In my humble opinion patchValue should alter the dirty flag is the contents is changed...
Is this a bug or the intended behavior?