Hi. Im having a problem with login form validation. Im trying to validate all my form fields but I Im missing something which cause an error. I would really like your kind help,
Thanks in advance.
Heres my code:
import wixWindow from 'wix-window'; import wixData from 'wix-data'; import { local } from 'wix-storage'; export function signup_click(event) { const validateEmail = (otherEmailElementId) => (value, reject) => { let otherEmailElement = $w(otherEmailElementId); if (value === otherEmailElement.value) { otherEmailElement.validity.valid = true; otherEmailElement.resetValidityIndication(); return; console.log("Email and Confirm Your Email fields do not match"); otherEmailElement.validity.valid = false; otherEmailElement.updateValidityIndication(); reject("Email and Confirm Email fields do not match"); }; $w("#mailvalidate").onCustomValidation(validateEmail("#mailreg")); $w("#mailreg").onCustomValidation(validateEmail("#mailvalidate")); $w('#dataset1').onBeforeSave(() => { if (!($w('#privatenamereg').valid && $w('#lastnamereg').valid && $w('#mailreg').valid && $w('#passwordreg').valid)) { let validationMessage = ''; if (!$w('#privatenamereg').valid || !$w('#lastnamereg').valid) validationMessage += 'please enter first name and last name*'; if (!$w('#mailreg').valid) { if (!$w('#mailreg').value) validationMessage += 'please enter a Valid mail address*'; else if ($w('#mailreg').value !== $w("#mailvalidate").value) { validationMessage += 'mail fields are not matching'; const validatePassword = (otherPasswordElementId) => (value, reject) => { let otherPasswordElement = $w(otherPasswordElementId); if (value === otherPasswordElement.value) { otherPasswordElement.validity.valid = true; otherPasswordElement.resetValidityIndication(); return; console.log("Password and Confirm Your Password fields do not match"); otherPasswordElement.validity.valid = false; otherPasswordElement.updateValidityIndication(); reject("Password and Confirm Password fields do not match"); }; $w("#passwordvalidate").onCustomValidation(validateEmail("#passwordreg")); $w("#passwordreg").onCustomValidation(validateEmail("#passwordvalidate")); $w('#dataset1').onBeforeSave(() => { if (!($w('#privatenamereg').valid && $w('#lastnamereg').valid && $w('#mailreg').valid && $w('#passwordreg').valid)) { let validationMessage = passwords are not matching'; if (!$w('#passwordreg').valid) { if (!$w('#passwordreg').value) validationMessage += 'please enter Password*'; else if ($w('#passwordreg').value !== $w("#passwordvalidate").value) { validationMessage += ' passwords are not matching*'; }
Hi, thanks for replay. The only thinf I've added is the export function at the beggining of the code to mekae sure it'll work when people press the button.
if you are using and copying this tutorial, tehn make sure that you check your code to make sure that it is matching with the tutorial.
https://www.wix.com/corvid/example/custom-validations
Start of your code above:
import wixWindow from 'wix-window'; import wixData from 'wix-data'; import { local } from 'wix-storage'; export function signup_click(event) { const validateEmail = (otherEmailElementId) => (value, reject) => { let otherEmailElement = $w(otherEmailElementId); if (value === otherEmailElement.value) { otherEmailElement.validity.valid = true; otherEmailElement.resetValidityIndication(); return;
Start of code from tutorial:
import wixWindow from 'wix-window'; import wixData from 'wix-data'; import { local } from 'wix-storage'; $w.onReady(function () { const validateEmail = (otherEmailElementId) => (value, reject) => { let otherEmailElement = $w(otherEmailElementId); if (value === otherEmailElement.value) { otherEmailElement.validity.valid = true; otherEmailElement.resetValidityIndication(); return;