B
B
Bogdan2018-03-15 19:57:54
Vue.js
Bogdan, 2018-03-15 19:57:54

Form validation?

Hello. Tell me please. I use Vee Validator, I need to validate individual fields on the form when the form is loaded ( hook mounted ) and for some reason it writes that the fields are invalid, although everything is fine there, but if I use validation for all fields ($validator.validateAll ), then the validation works correctly , but I only need it for individual fields.

<form id="demo">
  <div class="input-group">
    <div class="input-group-addon">
      Enter Password
    </div>

    <div class="input-fields">
      <input v-model='password' v-validate.initial="'required'" name="password" type="text" class="form-control" placeholder="Password">

      <input v-model='confirmation' v-validate.initial="'required|confirmed:password'" name="password_confirmation" type="text" class="form-control" placeholder="Password, Again" data-vv-as="password">
    </div>
  </div>

  <div class="alert alert-danger" v-show="errors.any()">
    <div v-if="errors.has('password')">
      {{ errors.first('password') }}
    </div>
    <div v-if="errors.has('password_confirmation')">
      {{ errors.first('password_confirmation') }}
    </div>
  </div>
</form>

Vue.use(VeeValidate);

var vueDemo = new Vue({
  el: '#demo',
  data: {
    password: '1',
    confirmation: '3'
  },
  mounted( ) {
      this.$validator.validate('password');
       this.$validator.validate('password_confirmation');
  }
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question