I
I
Ilya Loopashko2020-05-26 18:57:02
Vue.js
Ilya Loopashko, 2020-05-26 18:57:02

How to properly validate a Vue form?

I need to do form validation.

1. When creating a task, at least 10 characters. Red border.
5ecd3bc017bcd994761891.png

2. If correct, it was green
5ecd3c1453935406023570.png

3. And that the button would not be active until the correct value is entered.
5ecd3c3d06a6f675584094.png

jsfiddle code here

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-05-26
@deadloop

computed: {
  newTodoValid() {
    return this.newTodo.length >= 10;
  },
},

<input :class="newTodoValid ? 'valid' : 'not-valid'">
<button :disabled="!newTodoValid">

.valid {
  border: 2px solid green;
}

.not-valid {
  border: 2px solid red;
}

O
olenkill2, 2020-05-26
@olenkill2

If there are a lot of forms, then I advise you to use the vee-validate
plugin Lightweight, flexible. In general, cool stuff. But this is if there are more than one form)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question