sunmingtao / sample-code

3 stars 4 forks source link

vuelidate: cannot validate "required" checkbox field (Tricky) #116

Closed sunmingtao closed 4 years ago

sunmingtao commented 4 years ago

Followed https://www.udemy.com/course/vuejs-2-the-complete-guide/learn/lecture/8387040?start=0#overview

Couldn't get the checkbox validation working. It seems always valid.

However, downloaded and ran the finished project, it works as expected.

sunmingtao commented 4 years ago

Turns out the new vuelidate library (v. 0.7.5) considers false as a valid value as well. However, the old library used in the finished project (v. 0.6.1) considers false as an empty value.

Solution is using sameAs

terms: {
    sameAs: sameAs( () => true)
}

https://github.com/vuelidate/vuelidate/issues/332

rajiv-aglab commented 3 years ago

sameAs also not working... getting error as

TypeError: this.errorMessages[type] is not a function