0

I have a custom validation for if a condition is true. Based on that condition I would like to set disabled on a input field in a formgroup. If I use the condition with *ngIf it works fine but if I use the same condition with [disabled]= nothing is happening.

// working part
<div *ngIf="groupForm.errors?.validateForMr && (groupForm.touched || groupForm.dirty)" class="cross-validation-error-message alert alert-danger">
    Name cannot match alter ego.
</div>

// and the part I can't get to work
<input type="text" [disabled]="!groupForm.errors?.validateForMr" id="mr_nr" class="form-control" formControlName="mr_nr" (focus)="focusIn(2)" (focusout)="focusOut(2)">

Anyone have a suggestion?

Mikael
  • 25
  • 1
  • 6

1 Answers1

1

It is not wise to disable formControl in html page..

If you are using Reactiveforms you can try this code in your Component.

this.yourFormName.controls['yourFormControlName'].disable(); to disable input and this.yourFormName.controls['yourFormControlName'].enable(); to enable back.

Chetan Sharma
  • 161
  • 11