Skip to content

field validation based on another field condition #13

@thgpdr

Description

@thgpdr

It should be possible to validate sinbling fields based on a condition.

Something like this:

const User = 
    entity('Person', {
        name: field(String),
        hasChildren: field(Boolean),
        childrenNames: field([String]).when('hasChildren', {
            is: true, // possibility to use a function instead
            then: ({ validation: { presence: true } }),
            // otherwise: some other validation
        }),
    })

inspired on yup .when()

what do you guys think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Ready to code

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions