Hello,
I’m trying to finish up our website’s customer registration page, but running into a problem. I’m trying to use validation settings to keep the submit button disabled until all the text fields have been filled out. Here’s the code:
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady( function () {
//TODO: write your page related code here…
$w(‘#CustFName’).onChange(FinishEnableDisable)
$w(‘#CustLName’).onChange(FinishEnableDisable)
$w(‘#CustPhone’).onChange(FinishEnableDisable)
$w(‘#CustAdr1’).onChange(FinishEnableDisable)
$w(‘#CustCity’).onChange(FinishEnableDisable)
$w(‘#CustState’).onChange(FinishEnableDisable)
$w(‘#CustZip’).onChange(FinishEnableDisable)
});
function FinishEnableDisable() {
if ($w(‘#CustFName’).valid && $w(‘#CustLName’).valid && $w(‘#CustPhone’).valid && $w(‘#CustAdr1’).valid && $w(‘#CustCity’).valid && $w(‘#CustState’).value <=52 && $w(‘#CustZip’).valid) {
$w(‘#Submit’).enable()
} else {
$w(‘#Submit’).disable()
}
}
Also here are screen shots of the pattern validation settings I have defined. CustState is a dropdown menu with each state corresponding to a numerical value, as well as an option for Territories/Outlying Islands (51) Non-Us (52) and the placeholder “Select a state” (53). I did it this way so if the value is equal or less than 52, it’s valid and keeping it on the placeholder is invalid.
CustFName, CustLName, CustAdr1, and CustCity use this pattern validation (CusAdr1 has a character limit of 30)
CustPhone Pattern Validation
CustZip Pattern Validation