Below is my code. In the addEmployee.vue file, fields are there. Firstname , Middlename , Lastname. Among the three fields "Firtname & Lastname" has noraml tag. But "Middlename" has tag. Vee-validate "required" validation is working for the normal input tag fields but it's not working for Middlename field. What is the reason for this?
addEmployee.vue
<template>
<b-card>
<h4 slot="header" class="card-title">Employee</h4>
<b-row>
<b-col sm="3">
<b-form-group>
<label for="name">First Name </label>
<input type="text" id="" class="form-control" placeholder="Enter your name" v-validate="'required|Name'" name="Firstname">
<span v-show="errors.has('Firstname')" class="is-danger">{{ errors.first('Firstname') }}</span>
</b-form-group>
</b-col>
<b-col sm="3">
<b-form-group>
<label for="name">Middle Name </label>
<b-form-input type="text" id="" placeholder="Enter your name" v-validate="'required|Name'" name="Middlename">
<span v-show="errors.has('Middlename')" class="help is-danger">{{ errors.first('Middlename') }}</span></b-form-input>
</b-form-group>
</b-form-group>
</b-col>
<b-col sm="3">
<b-form-group>
<label for="name">Last Name </label>
<input type="text" id="" class="form-control" placeholder="Enter your middle name" v-validate="'required|Name'" name="Lastname">
<span v-show="errors.has('Lastname')" class="help is-danger">{{ errors.first('Lastname') }}</span>
</b-form-group>
</b-col>
</b-row>
<input type="submit" value="Submit" @click="validateForm">
</b-card>
</template>
<script>
import Vue from 'vue'
import VeeValidate from 'vee-validate';
Vue.use(VeeValidate);
export default {
name: 'addEmpl'
},
methods: {
validateForm() {
this.$validator.validateAll().then((result) => {
if(!result){
alert('not submitted')
return
}
alert('submitted')
}).catch(() => {
});
}
}
}
</script>
<style lang="scss" scoped>
.is-danger{
color: RED;
}
</style>
Thanks in advance.
you have to close b-form-input before span ;
become :
delete duplicated /b-form-group also (not critical) , now it works :)