I created a new site member and registered. The chrome inspector console showed that a valid unit number had been entered and the registration completed successfully. When I viewed the site contact, the unit number was blank, see below. This used to work a couple of months back (no changes to my code). Any suggestions greatly appreciated. --Jeff.
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
$w.onReady(function () {
showUnitNumber();
});
export function showUnitNumber() {
console.log("showUnitNumber()");
console.log("unitOwner: " + $w('#unitOwner').checked);
console.log("resident: " + $w('#unitResident').checked);
if ($w('#unitOwner').checked === true || $w('#unitResident').checked === true) {
console.log("showing unit number");
$w('#unitNumber').show("");
} else {
console.log("hiding unit number")
$w('#unitNumber').hide("");
}
}
export function unitOwner_change(event) {
showUnitNumber();
}
export function unitResident_change(event) {
showUnitNumber();
}
export async function submit_click(event) {
console.log("clicked submit");
let emails = [];
let labels = [];
let phones = [];
var pageValid = true;
$w('#validationMessages').collapse();
const unitOwner = $w('#unitOwner').checked;
const unitResident = $w('#unitResident').checked;
const hoaBoard = $w('#hoaBoard').checked;
const assocMgmt = $w('#assocManagement').checked;
// insert labels
if (unitOwner === true) {
labels.push("UnitOwner");
}
if (unitResident === true) {
labels.push("Resident");
}
if (hoaBoard === true) {
labels.push("HoaBoard");
}
if (assocMgmt === true) {
labels.push("AssocMgmt");
}
var unitNumberRequired = unitOwner || unitResident;
var atLeastOneChecked = unitOwner || unitResident || hoaBoard || assocMgmt;
console.log("atLeastOneChecked: " + atLeastOneChecked);
var validationMessage = '';
var firstName = $w('#firstName').value;
var firstNameValid = $w('#firstName').valid;
if (!firstName || firstName.length === 0 || !firstNameValid) {
validationMessage += 'Please provide your first name\n';
}
var lastName = $w('#lastName').value;
var lastNameValid = $w('#lastName').valid;
if (!lastName || lastName.length === 0 || !lastNameValid) {
validationMessage += 'Please provide your last name\n';
}
var phone = $w('#phone').value;
var phoneValid = $w('#phone').valid;
if (!phone || phone.length === 0 || !phoneValid) {
validationMessage += 'Please provide your phone number\n';
}
var email = $w('#email').value;
var emailValid = $w('#email').valid;
if (!email || email.length === 0 || !emailValid) {
validationMessage += 'Please provide your email address\n';
}
var password = $w('#password').value;
var passwordValid = $w('#password').valid;
if (!password || password.length === 0 || !passwordValid) {
validationMessage += 'Please provide your password\n';
}
if (!atLeastOneChecked) {
validationMessage += 'Please check at least one box to qualify for membership\n';
}
if (hoaBoard && !unitOwner) {
validationMessage += 'An HOA Board member must also be a Unit Owner\n';
}
var unitNumber = $w('#unitNumber').value;
console.log("unitNumber: " + unitNumber);
var unitNumberValid = $w('#unitNumber').valid;
if (unitNumberRequired) {
if (!unitNumber || unitNumber.length === 0 || !unitNumberValid) {
validationMessage += 'Please provide your Unit Number\n';
}
}
pageValid = validationMessage.length === 0;
if (pageValid) {
// check for duplicate email
const emailQueryResults = await wixData.query("EmailDatabase").eq("emailAddress", email).find().catch((err) => {
validationMessage += "In email query catch block";
validationMessage += err;
$w('#validationMessages').text = validationMessage;
$w('#validationMessages').expand();
});
if (emailQueryResults.length > 0) {
validationMessage += 'Your account already exists, found duplicate email address\n';
}
}
pageValid = validationMessage.length === 0;
if (!pageValid) {
$w('#validationMessages').text = validationMessage;
$w('#validationMessages').expand();
}
// register as member using form data
if (pageValid) {
console.log("validation passes, registering new member...");
email = email.toLowerCase();
emails.push(email);
phones.push(phone);
const registerResult = await wixUsers.register(email, password, {
"contactInfo": {
"firstName": firstName,
"lastName": lastName,
"emails": emails,
"labels": labels,
"phones": phones,
"mainPhone": phone,
"UnitNumber": unitNumber
}
}).catch((err) => {
validationMessage += "In register catch block";
validationMessage += err;
console.log(validationMessage);
$w('#validationMessages').text = validationMessage; //validationMessage;
$w('#validationMessages').expand();
});
if (registerResult.status === "Pending" || registerResult.status === "Approved") {
// save email address
let options = {
"suppressAuth": true,
"suppressHooks": true
};
let toInsert = {
"emailAddress": email
};
wixData.insert("EmailDatabase", toInsert, options).catch((err) => {
validationMessage += err;
$w('#validationMessages').text = validationMessage;
$w('#validationMessages').expand();
console.log(validationMessage);
});
pageValid = validationMessage.length === 0;
if (pageValid) {
console.log("opening ack lightbox");
wixWindow.openLightbox("200RLD Resistration Ack");
console.log("closing reg lightbox");
wixWindow.lightbox.close();
}
}
}
}