Subscribe on changes!

Prop cross-validation

avatar
Feb 18th 2021

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
    }
},
avatar
Feb 18th 2021

It wasn't possible in Vue 2 (https://github.com/vuejs/vue/issues/6787) but I think this would be really helpful

avatar
Feb 18th 2021

Amazing ❤️ I'll give this a go.

avatar
Jan 4th 2024

I think this can be closed now since https://github.com/vuejs/core/pull/3258 has been merged and released as part of v3.4

avatar
Jan 4th 2024

Weird this didn't auto close once the change went into main. I guess it's because it wasn't in the commit message, only in the PR description