Hi all
I am trying to edit the specific error text message for the e-mail field in a form. By this I mean the error message when the e-mail field is empty, not the general message when something is not correctly filled in in the form.
Thank you in advance
Add a custom validation and set your own message.
$w("#myElement").onCustomValidation( (value, reject) => {
if(value === "evil")
{ reject("Evil is invalid");
}
});
Read more about custom validation at ValidatableMixin - Velo API Reference - Wix.com
I’m trying to do a similar thing with a date picker on my form representing the user’s date of birth…
I have functions set up that disable the submit button if the date selected means they are under the age of 21. Everything works perfectly there.
But now I want the date picker to also show the error state if the age is below 21. I can’t work out how to do this.
Here is the working code I have for getting the user’s age and disabling the submit button:
$w("#dobDatePicker").onChange((event) => {
let newValue = event.target.value; // "new value"
let age = getAge(newValue);
console.log('age: ', age);
if(age >= 21) {
$w('#submitButton').enable();
}
else {
$w('#submitButton').disable();
}
});
function getAge(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}
I tried adding the following but it didn’t work…
$w("#dobDatePicker").onChange((event) => {
let newValue = event.target.value; // "new value"
let age = getAge(newValue);
console.log('age: ', age);
if(age >= 21) {
$w('#submitButton').enable();
}
else {
$w('#submitButton').disable();
$w("#dobDatePicker").onCustomValidation( (value, reject) => {
if(age <= 21) {
value = "invalid";
}
if(value === "invalid") {
reject("Under 21 years of age");
}
} );
let isValid = $w("#dobDatePicker").valid;
$w("#dobDatePicker").updateValidityIndication();
}
});
Any help would be amazing 
Hey, if you did resolve the above described issue, please do post the solution, thank you