question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass an object to custom validation

See original GitHub issue

Versions:

  • VueJs: #.#.#
  • Vee-Validate:

Description:

Hello logaretm, So firstly i want to thank you for you incredible repository, I’m using vuetify with vee-validate, I confess that you have the best vuejs validation library in all the web, It is complete with an incredible documentation. I have a question : There is a way to passe an object to custom validation, because I create my inputs fields with a loop and each input contains an object

For example

<p v-for="inventory in List">
<v-text-field
    :label="'Stock ('+inventory.currentStock+' '+inventory.type+')'"
    :name="inventory.nameStock"
    v-model="inventory.stock"
    v-bind:rules="inventory.rulesStock"
    v-validate="'required|custom_valid'"
></v-text-field>
</p>

There is for example a directive like : v-pass-args-to-custom-validation=“inventory”? Or something that can help me in my case? Thanks so much in advance.

Steps To Reproduce:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

23reactions
logaretmcommented, May 14, 2017

Thank you for the kind words 😄 . You can validate objects, if your input knows how to deal with them. for example I can’t see how the text field component would be able to deal with an object, eventually you are validating the object stock value which is a string/number.

anyways, you can create a custom rule that accepts said objects as params:

const myRule = (obj) => {
    // validate stuff
};

and in your html you can use the object form:

<v-text-field
    :label="'Stock ('+inventory.currentStock+' '+inventory.type+')'"
    :name="inventory.nameStock"
    v-model="inventory.stock"
    v-bind:rules="inventory.rulesStock"
    v-validate="{
        required: true,
        custom_rule: [inventory]
    }"
></v-text-field>
15reactions
jayGoriocommented, Aug 8, 2017

Can I validate a pdf file using vee-validate?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing Objects to Custom Validator in WTForms
Here is the custom validator that works when the user is editing their own account from a different form class: # Custom validation...
Read more >
Custom Rules - VeeValidate
You can recieve an object instead of an array for your validation rule by providing a paramNames array in the extend options (third...
Read more >
Part #3 - Rule Objects Custom Laravel Validation - YouTube
Adding custom validation using the rule object is an alternative to using ` Validator ::extend`. By using Rule Objects you can make creating ......
Read more >
Validation - Laravel - The PHP Framework For Web Artisans
Validating Nested Array Input; Error Message Indexes & Positions. Validating Files; Validating Passwords; Custom Validation Rules. Using Rule Objects; Using ...
Read more >
Spring MVC Custom Validation - Baeldung
Creating a custom validator entails rolling out our own annotation and using it in our model to enforce the validation rules. So let's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found