I have a problem with custom validation in vee-validate. I have this method, which is checking if email already exists in my database, but i'm keep getting error Error in callback for watcher "email": "TypeError: Cannot read property 'then' of undefined"
This is my HTML code, which has validation emailAlreadyExists
<div class="prepend-icon">
<p :class="{ 'control': true }">
<input v-validate="'required|email|emailAlreadyExists'"
:class="{
'form-control input-lg': true,
'input': true,
'is-danger': errors.has('email')
}"
name="email" type="email"
v-bind:placeholder="$root.trans.translate('enterYourEmail')"
v-model="email"
/>
<i class="nc-icon-outline ui-1_email-83"></i>
<span v-show="errors.has('email')" class="help-block with-errors">
{{ errors.first('email') }}
</span>
</p>
</div>
And this is my validation inside created method
created() {
this.$validator.extend('emailAlreadyExists', {
getMessage: field => field + 'Email already exists.',
validate: value => {
let params = new URLSearchParams();
params.append('email', value);
this.$http.post(this.$apiUrl + `rest/api/public/User/checkIfUserExists`, params, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
})
}
})
}
And this is an error i'm keep getting in console log
You can see whole file here: PasteBinLink
Can someone point what I'm doing wrong, that I'm keep getting this error? If you need any additional informations please let me know and i will provide. Thank you!