Skip to content

Prop cross-validation #3254

@nandi95

Description

@nandi95

What problem does this feature solve?

This issue I had frequently in vue 2 as well but never really questioned it.
Is there a reason why the prop validator doesn't have access to the other props? If so I could not find any related discussion.

This would be very helpful if I would like to validate a prop one way if another prop is present, and another way if it isn't.

As far as I can tell the props can be passed to the validateProp from here

There is currently a workaround using watchers, but in my opinion that isn't as clean as this would be.

I would be happy to PR this if wanted.

What does the proposed API look like?

prop: {
    type: Array,
    required: true,
    validator: (value, props) => {
        return props.someBooleanFlag
            ? ... validate one way
            : ... validate another way
    }
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions