Answer the question
In order to leave comments, you need to log in
Vuejs input field validation?
Help me figure it out, in general I implemented this thing: There is an "AppInput" component, it was necessary to implement validation on it through the input parameters
AppInput.vue
<input
class="field"
:class="value ? 'has-data' : ''"
:type="type"
:required="reqired"
v-model="input"
@change="validate"
>
methods: {
validate (e) {
if (this.rules) {
this.message = this.rules.map(fn => fn(this.input))
}
}
}
rules: [
v => !! v || 'Поле обязательное',
v => v.length >= 8 || '8 символов'
]
Answer the question
In order to leave comments, you need to log in
this.message = this.rules.map(n => n(this.input)).find(n => n !== true);
1) Here is their implementation https://github.com/vuetifyjs/vuetify/blob/master/p...
2) You can look for ready-made solutions not to cut another bike
3) Return the first message if it is false, and then do not iterate over validators
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question