Your prozess step by step…
- When page is ready yoo start the validation-check.
$w.onReady(()=>{....});
- You have a REGISTRATION-BUTTON on your page (regButton).
When clicked → The registration-prozess starts…
$w.onReady(()=>{
$w('#regButton').onClick(()=>{
register(); // <-- REGISTRATION-START onClick!
});
});
- Function register() starts…
function register() {
if (valuesValid()) {
let email = $w('#email').value
let password = $w('#password').value
authentication.register(email, password)
.then((user) => {
const toInsert = {
"_id": user.member._id,
"_owner": user.member._id,
"loginEmail": email,
"password": password,
"firstName": $w('#forename').value,
"nickname": $w('#nickname').value,
"age": $w('#age').value,
"gender": $w('#gender').value,
"Man": $w('#gender').value,
"Woman": $w('#gender').value,
"sexualOrientation": $w('#orientation').value,
"country": $w('#country').value,
"state": $w('#state').value,
"language": $w('#language').value,
};
// add the item to the collection
wixData.insert("Members", toInsert)
.then((item) => {
if (wixUsers.currentUser.loggedIn) {
wixLocation.to(`/members/account/${item._id}`);
} else {
let email = $w('#email').value;
let password = $w('#password').value;
wixUsers.login(email, password).then(() => {
wixLocation.to(`/members/account/${item._id}`);
}).catch((err) => {
console.error(err);
$w('#errorMessage').text = "Couldn't log you in: " + err
errorMessage()
})
console.log("User is logged in");
}
})
.catch((err) => {
console.error(err);
$w('#errorMessage').text = "Somehing isn't right on your end: " + err
errorMessage()
});
})
} else {
$w('#errorMessage').text = "Somehing isn't right on your end: There's an Invalid or Missing Property"
errorMessage()
}
}
- First running the VALIDATION-CHECK…
function valuesValid() {
return $w('#email').valid &&
$w('#password').valid &&
$w('#forename').valid &&
$w('#age').valid &&
$w('#gender').valid &&
$w('#orientation').valid &&
$w('#country').valid &&
$w('#language').valid &&
$w('#nickname').valid &&
$w('#state').valid;
}
- If all values are VALID… → start REG-PROCESS…
let email = $w('#email').value
let password = $w('#password').value
authentication.register(email, password)
- Then do the following… Inserts USER-DATA into “Members”
.then((user) => {
const toInsert = {
"_id": user.member._id,
"_owner": user.member._id,
"loginEmail": email,
"password": password,
"firstName": $w('#forename').value,
"nickname": $w('#nickname').value,
"age": $w('#age').value,
"gender": $w('#gender').value,
"Man": $w('#gender').value,
"Woman": $w('#gender').value,
"sexualOrientation":$w('#orientation').value,
"country": $w('#country').value,
"state": $w('#state').value,
"language": $w('#language').value,
};
wixData.insert("Members", toInsert)
.then((item) => {
if (wixUsers.currentUser.loggedIn){
wixLocation.to(
`/members/account/${item._id
}`);
}
else {
let email = $w('#email').value;
let password = $w('#password').value;
wixUsers.login(email, password)
.then(() => {
wixLocation.to(
`/members/account/${item._id}`
);
})
.catch((err) => {console.error(err);
$w('#errorMessage').text = "Couldn't log you in: " + err errorMessage()})
console.log("User is logged in");
}
})
.catch((err) => {
console.error(err);
$w('#errorMessage').text = "Somehing isn't right on your end: " + err
errorMessage()
});
})
} else {
$w('#errorMessage').text = "Somehing isn't right on your end: There's an Invalid or Missing Property"
errorMessage()
}
}
Till here everything seems to make sense and is logical, but where the hell is your REPEATER-CODE ?
Or do you expect, that if you connect your REPEATER trough the properties-panel, and the repeater will automaticaly know what to do with the recieved data? —> Of course not!
This is in most cases the same problems, when someone tries to mix settings inside PROPERTIES-PANEL and CODE.
You will have to DISCONNECT your repeater on your page, which will surely be connected through the property-panel at current moment.
After you have disconnected it from PROPERTY-PANEL, you will have to code your own CUSTOM-FUNCTIONS, telling the repeater what to do with the recieving data.
After your data was inserted into DB, you can query the data out of this DB using Wix-Data-Api
When you have your data-package, which you want to be loaded into your repeater, then you will need another code-part…
$w('#yourRepeaterIDhere).data = "your queried data from DB ("Members")";
$w('#yourRepeaterIDhere).onItemReady($item, itemData, index()=>{
//...and here you define all the repeater-elements to be shown...
$item('#textElement').text= itemData.title;
$item('#imageElement').src= itemData.imageField;
$item('#another element inside repeater').........
// and also here you can write the IF-ELSE-Statement to differ between WOMEN and MEN.
if(itemData.xxxxxx === "WOMAN"){............}
else {.............}
})
Something like that 