I'm looking to establish specific rules within a mixin for my components.
Allow me to provide a straightforward example of my request:
The code snippet:
<v-text-field :rules="[nbRules, requiredRules]" outlined v-model="name" label="Ticket Name" required></v-text-field>
...
requiredRules: [
v => !!v || 'This field is mandatory',
],
nbRules: [
v => v.length <= 10 || 'Name must be less than 10 characters',
],
However, as per the documentation
This feature accepts an array of functions that take an input value and either return true / false or a string containing an error message
, I attempted to pass an array but encountered the following error:
Rules should return a string or boolean, received 'object' instead
I also experimented with using computed properties like :
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
},
Yet, the same error persisted
Is there a solution to achieving my desired outcome?
Thank you