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

Validator fails when parameter is a 1-element array #2716

Closed
Skeeve opened this issue Apr 7, 2020 · 1 comment
Closed

Validator fails when parameter is a 1-element array #2716

Skeeve opened this issue Apr 7, 2020 · 1 comment
Labels
🐛 bug Unintended behavior

Comments

@Skeeve
Copy link

Skeeve commented Apr 7, 2020

Versions

  • vee-validate: 3.2.5
  • vue: 2.6.11

Describe the bug
I have a custom validator requiring an array of objects as parameter. When this array has more than one element, everything works fine. Has it just one element, the validator receives just the one element, not an array with onw element.

To reproduce

This is the validator

extend("notOneOf", {
  validate(val, args) {
    return !args.existingOwners.some(function(e) {
      return (
        0 == e.owner.localeCompare(val, undefined, { sensitivity: "accent" })
      );
    });
  },
  params: ["existingOwners"],
  message: "«{_value_}» already exists."
});

The array of objects looks like this:

  data() {
    return {
      owner: "",
      owners: [
        { owner: "a",},
        { owner: "b",},
        
      ]
    };
  },

And the input field:

        <validation-provider
          :rules="{ required: true, notOneOf: owners }"
          v-slot="{ errors }"
        >
          <label>
            Owner
            <input
              type="text"
              placeholder="Enter a (new) owner."
              v-model="owner"
              name="owner"
              minlength="4"
            />
            <span :class="{ alert: errors[0] }">
              {{ errors[0] }}
            </span>
          </label>
        </validation-provider>

Expected behavior
The validator works for 2 and more element array. When there is just one element I get

TypeError: args.existingOwners.some is not a function app.js line 354 > eval:45:33

Checking with console it reveals that the validator receives just the one element of the array, not an array.

Desktop (please complete the following information):

  • OS: MacOS 10.14.16
  • Browser FireFox
  • Version 74.0.1

Additional context
"Compiling" vue in a docker container, using it in another docker container with Mojolicious.

@logaretm logaretm added the 🐛 bug Unintended behavior label Apr 11, 2020
@logaretm
Copy link
Owner

Thank you for reporting this issue, I have identified the problem and fixed it.

It should be relased in the next patch release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants