The problem is that in this case the validation always succeeds and value.value is always undefined
Mixin:
import { useField, useForm } from 'vee-validate';
export default {
methods: {
async validateField(fieldName, rules) {
try {
const { value } = useField(fieldName, rules);
const { validate } = useForm();
if (!value) {
console.log(`Field ${fieldName} is invalid`);
return false;
}
const success = await validate(fieldName, value);
if (success) {
console.log(`Field ${fieldName} is valid`);
return true;
} else {
console.log(`Field ${fieldName} is invalid`);
return false;
}
} catch (error) {
console.error(error);
return false;
}
},
resetFields() {
const { resetForm } = useForm();
resetForm();
}
}
};
Part of component:
<b-form-input
id="email"
type="email"
v-model.trim="form.email"
placeholder="Enter email"
@input="validateField('email', 'required|min:6')"
/>
<script>
import ValidationNew from "@/mixins/validation-new";
export default {
mixins: [ValidationNew],
data() {
return {
form: {
email: '',
}
}
}
}
</script>
I tried to find similar examples, but I didn’t find anything, I don’t even know what to do here because I’m not particularly familiar with the Composition API and Vee-validate 4
New contributor
getJinxed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.