Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Disabled Required Control is invalid

Tags:

angular

I'm using Angular 2 Reactive Form. I have a form Control which is defined with required validation. When the user loads the form and this control is populated Angular consider the form control as valid. (Which is good!)

However, if the form control is populated and it's also disabled angular consider it as invalid? (W-H-Y?)

Have anyone encountered this? Is this a bug or by design?

Thanks!

like image 700
MasterOfPuppets Avatar asked Apr 03 '17 13:04

MasterOfPuppets


People also ask

What is invalid in angular?

Every time the value of a form control changes, Angular runs validation and generates either a list of validation errors that results in an INVALID status, or null, which results in a VALID status.


1 Answers

This is by design, as per the W3C standard disabled inputs are not valid. In Angular you can use FormGroup.getRawValues() if you want to retrieve all values regardless of whether they are disabled or not.

Alternatively consider using the readonly attr instead.

like image 188
P. Moloney Avatar answered Nov 04 '22 00:11

P. Moloney