Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prop cross-validation #3254

Closed
nandi95 opened this issue Feb 18, 2021 · 4 comments · Fixed by #3258
Closed

Prop cross-validation #3254

nandi95 opened this issue Feb 18, 2021 · 4 comments · Fixed by #3258
Labels
✨ feature request New feature or request

Comments

@nandi95
Copy link
Contributor

nandi95 commented Feb 18, 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
    }
},
@posva
Copy link
Member

posva commented Feb 18, 2021

It wasn't possible in Vue 2 (vuejs/vue#6787) but I think this would be really helpful

@posva posva added the ✨ feature request New feature or request label Feb 18, 2021
@nandi95
Copy link
Contributor Author

nandi95 commented Feb 18, 2021

Amazing ❤️
I'll give this a go.

nandi95 added a commit to nandi95/vue-next that referenced this issue Sep 28, 2021
Added all props to the prop validator as a second argument

vuejs#3254
@Lehoczky
Copy link

Lehoczky commented Jan 4, 2024

I think this can be closed now since #3258 has been merged and released as part of v3.4

@posva
Copy link
Member

posva commented Jan 4, 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

@posva posva closed this as completed Jan 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✨ feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants