Description
Hey Luca,
I have a bit of an edge case here and I'm not sure if there's anything that can be done to address it. I have a form that has a field that is required. However, that field is disabled until a value from another field is selected, then it is enabled.
If I choose a value for the other field first and the disabled field is enabled, the validation works fine.
If I try to submit the form and the validation runs before that field can be enabled, I get the following error in the console and validation will not work for the field that was disabled...even after eventually being enabled:
Cannot convert undefined or null to object
It's perfectly understandable why it's doing this...technically a disabled form field is ignored, even when the form values are submitted. The problem is that directives cannot be assigned conditionally. So I cannot only apply the validation directive when the field is enabled.
The only work-around I have come up with is creating a dummy field that looks disabled in addition to an enabled field and surround each one with an *ngIf depending on if the value of the other field is present. Feels like a hack to me though.
Might you have any suggestions on how to handle this? Thanks for any suggestions.