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

required_if fails if configuration is object, and values are not strings #2362

Closed
davestewart opened this issue Sep 22, 2019 · 0 comments
Closed
Labels
🐛 bug Unintended behavior ✨ enhancement a "nice to have" feature

Comments

@davestewart
Copy link
Collaborator

davestewart commented Sep 22, 2019

Versions

  • vee-validate: 3.0.6
  • vue: latest

Describe the bug
required_if fails if configuration is an Object, and the values parameter values are not strings

Expected behavior
We get a validation error, even though the value 1 is in the values array

Demo link
https://jsfiddle.net/davestewart/yknL0ph9/28/

Additional context
The use-case for us is manually validating models, so inputs are NOT forms, with numbers being numbers, etc.

This causes required_if to fail as the comparator converts the value to a trimmed string:

A fix could be to map the array to a string as well, or do a "loose" comparison, using something like:

const required = values.some(value => value == String(target).trim())

Also, values could be optional, which would allow required_if to work if the value was just present (rather than being a specific value):

const required = !values || values.some(value => value == String(target).trim())
@logaretm logaretm added ✨ enhancement a "nice to have" feature 🐛 bug Unintended behavior labels Sep 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unintended behavior ✨ enhancement a "nice to have" feature
Projects
None yet
Development

No branches or pull requests

2 participants