1

It appears that Validators set on a disabled input do not trigger automatically (upon setting value programmatically). Regardless of setting the value in code, the form control state is always untouched pristine. Is there a way to force it?

lairtech
  • 2,337
  • 4
  • 25
  • 38

1 Answers1

0

You could try forcing a change detection, similar to what $scope.$digest() did in angularjs. Look at this answer https://stackoverflow.com/a/34829089/5423717

Derek J.
  • 1,400
  • 1
  • 14
  • 23
  • 1
    Thanks for the tip. Unfortunately I tried detect changes and it didn't work – lairtech Jan 17 '18 at 18:09
  • Do you have a function that checks if the form control is valid or not? If so you can populate the disabled form control and then check the validation using the function after populating it. – Derek J. Jan 17 '18 at 18:13
  • 1
    Like so `isFieldValid(field: string) { return !this.form.get(field).valid && this.form.get(field).touched; }` – Derek J. Jan 17 '18 at 18:14
  • Problem is for disabled FormControl, the state is always pristine, even after calling setValue() – lairtech Jan 17 '18 at 18:23