javascript - Vuetify : Is it possible to add many rules from data on a text component with vuetify? - Stack Overflow

I need to define rules in a mixin for my ponents.Here is a simple example of my requestThe code : <

I need to define rules in a mixin for my ponents.

Here is a simple example of my request

/

The code :

<v-text-field :rules="[nbRules, requiredRules]" outlined v-model="name" label="Nom du ticket" required></v-text-field>

...

requiredRules: [
  v => !!v || 'Le champs est obligatoire',
],
nbRules: [
  v => v.length <= 10 || 'Name must be less than 10 characters',
],

However, according to the documentation

Accepts an array of functions that take an input value as an argument and return either true / false or a string with an error message

, I have the possibility of passing an array but there, I have the error:

Rules should return a string or boolean, received 'object' instead

I also tried to use the properties puted as :

customRules(nb = 10) {
    const rules = [];

    if (nb) {
        const rule =
            v => (v || '').length <= nb ||
                `A maximum of ${nb} characters is allowed`

        rules.push(rule)
    }
    return rules
},

But same error

Is there a way to get what I want?

Thank you

I need to define rules in a mixin for my ponents.

Here is a simple example of my request

https://jsfiddle/alexisgt01/0tg4ovnz/2/

The code :

<v-text-field :rules="[nbRules, requiredRules]" outlined v-model="name" label="Nom du ticket" required></v-text-field>

...

requiredRules: [
  v => !!v || 'Le champs est obligatoire',
],
nbRules: [
  v => v.length <= 10 || 'Name must be less than 10 characters',
],

However, according to the documentation

Accepts an array of functions that take an input value as an argument and return either true / false or a string with an error message

, I have the possibility of passing an array but there, I have the error:

Rules should return a string or boolean, received 'object' instead

I also tried to use the properties puted as :

customRules(nb = 10) {
    const rules = [];

    if (nb) {
        const rule =
            v => (v || '').length <= nb ||
                `A maximum of ${nb} characters is allowed`

        rules.push(rule)
    }
    return rules
},

But same error

Is there a way to get what I want?

Thank you

Share Improve this question asked Dec 27, 2019 at 10:21 Alexis GatuingtAlexis Gatuingt 5471 gold badge7 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

What you doing now is passing array containing 2 other arrays into rules while Vuetify expects array of functions.

You need to merge two arrays first. Easiest way to do it is using spread syntax:

<v-text-field :rules="[...nbRules, ...requiredRules]" outlined v-model="name" label="Nom du ticket" required></v-text-field>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745282032a4620332.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信