Skip to content

Validation on disabled fields that become enabled #21

Open
@psenechal

Description

@psenechal

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions