I have a reactive form with Datepicker
<div class="form-group">
<label class="form-control-label" for="field_dataAtivacao">Data Ativação</label>
<div class="input-group">
<input id="field_dataAtivacao" type="text" class="form-control" name="dataAtivacao" ngbDatepicker #dataAtivacaoDp="ngbDatepicker" formControlName="dataAtivacao"/>
<span class="input-group-append">
<button type="button" class="btn btn-secondary" (click)="dataAtivacaoDp.toggle()">
<fa-icon [icon]="'calendar-alt'"></fa-icon>
</button>
</span>
</div>
</div>
Form control without validator
editForm = this.fb.group({
dataAtivacao: null,
});
The field is empty but always is required. I tried this solution but without success
EDIT
The above example works normally when I don't use the patch value method to update the form.
Like this example of the comments
The problem occurs when I need to update the form using the patchValue
method.
this.editForm.patchValue({
dataAtivacao: cliente.dataAtivacao,
});
When I change for null
works normally but I need to show the date and allows update the form with the current selected
this.editForm.patchValue({
dataAtivacao: null,
});