So I’ve persevered and I’m actually SO close to solving the issue I’ve had with populating text elements after form submission…
It seems as though the correct item is now being retrieved from the database but not all of the text elements are being populated:
The blue circle shows the correct data that has been successfully set as the element’s text. The red circles show the text elements that have not been set and remained as the example text created within the editor - As you can see, only 4 out of the 14 text elements have been successfully populated using the data retrieved by the code.
Here is the relevant piece of code I am using to retrieve the data item and display it in the text elements:
function populateRegConfirmation() {
if (($w("#programSelectDropdown").value==='Soccer')) {
const dobOptions = {day: "2-digit", month: "2-digit", year: "numeric"};
// Get current user.
let user = wixUsers.currentUser;
let userId = user.id;
user.getEmail()
.then((email) => {
let userEmail = email; // "user@something.com"
console.log(userEmail);
console.log(userId);
// Filter dataset to show items created by current user.
// get last item by current user.
wixData.query("soccerMembersDatabase")
.eq("email", userEmail)
.find()
.then( (results) => {
if(results.items.length > 0) {
let details = results.items[0];
$w("#name").text = details.firstName + " " + details.lastName;
$w("#phone").text = details.phone;
$w("#email").text = details.email;
$w("#address").text = details.address + ", " + details.city + ", " + details.postCode;
$w("#dob").text = details.birthDate([], dobOptions).toDateString;
$w("#gender").text = details.gender;
$w("#ecName").text = details.emergencyContactName;
$w("#ecPhone").text = details.emergencyContactPhone;
$w("#ecRelationship").text = details.emergencyContactRelationship;
$w("#goalieStatus").text = details.goalkeeper;
$w("#skillLevel").text = details.skillLevel;
$w("#regRefNo").text = details.id;
$w("#program").text = details.program.toString();
$w("#totalDue").text = details.paymentDue;
} else {
// handle case where no matching items found
}
} )
.catch( (err) => {
let errorMsg = err;
} );
})
}
}
I am not getting any errors within the editor coding panel or in the preview console.
I have no idea why it would be successfully running the first 4 lines of code within “if(results.items.length > 0)” but not any others after that.
I’d really appreciate any help with this mystery!
