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

String validation with empty rule ('||') causes an error #2386

Closed
davestewart opened this issue Sep 28, 2019 · 1 comment · Fixed by #2389
Closed

String validation with empty rule ('||') causes an error #2386

davestewart opened this issue Sep 28, 2019 · 1 comment · Fixed by #2389
Labels
✨ enhancement a "nice to have" feature 🛳 In PR This issue is being addressed in a PR

Comments

@davestewart
Copy link
Collaborator

davestewart commented Sep 28, 2019

Versions

  • vee-validate: 3
  • vue: 2

Describe the bug

We have to build up rulesets based on conditions that change at runtime, for example:

const rules = 'numeric'
if (x) {
  rules += '|required' // rules is 'numeric|required'
}

This works fine for rules where the initial condition has a validator.

But if we start with an empty string (no validation, but we may later want it to be required) we get Error: No such validator '' exists:

const rules = ''
if (x) {
  rules += '|required' // first rule is ''
}

Expected behavior

As there could be quite complex conditions to when we build the rules, it would be useful if the "empty" rule was simply ignored:

const rulesIn = 'numeric||min:0||||max:100||'
const rulesOut = 'numeric|min:0|max:100'

The rules could be easily filtered using a function, but should this filtering be built into the library?

Demo link

Additional context

I also wrote a function which converted all rules to objects but this felt like overkill for many of our much simpler rulesets.

@davestewart davestewart changed the title Empty string validation with | causes an error String validation with empty rules causes an error Sep 28, 2019
@davestewart davestewart changed the title String validation with empty rules causes an error String validation with empty rule ('||') causes an error Sep 28, 2019
@davestewart
Copy link
Collaborator Author

Would be worth looking at this in conjunction with #2388

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement a "nice to have" feature 🛳 In PR This issue is being addressed in a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants