I really need help to this easy code line, that I am struggling with
Basically I have a registration form that allows users to register their personal data and to choose (by two dropdowns) a committee of the United Nations and a Country. The first dropdown corresponds to the committees, and the option habilitates specific countries that belongs to that committee. Because its a registration form I need to take the options of the user and save them in a data base, but the fields of committee and countries already have options to let the user choose I just need to safe in a another database the preferences of the users. This database that stores the option shown in the to dropdowns to let the users choose its the following one:
So, as you can see basically I have 3 fields, one its corresponding to the committee of the UN (Sorry my DB is in Spanish), the other one is corresponding to the Country that is in that committee and the last one its called “state” with is a boolean type that allows me to filter later the data. This last field is key to me, because later I can only show the countries that have not being selected. So you can see that for example France its not going to be shown to an user, but the other countries are going to be shown. This allows me to control and only let user select options that are available.
The code that I used for this filter its the following one:
function uniqueDropDown2 (){
wixData.query(“ComitesyPaises”)
.eq(“state”, false )// This is the important part
.contains(“comite”, $w(“#Comite”).value)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#PaisComite”).options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.paisComite);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
Now, what I am basically struggling with is that : I can only set the “state” rows corresponding to the country that is already registered by hand and need to do it automatically.
So, somehow I need to make that when an user selects a country (this means an option in the second dropdown) and presses the button submit, the row next to the selected country (the one that is in the state field) is set it as “true” (this means that the checkbox is marked). So for example if an user chooses USA and presses the submit button, the row next to it in the Data Base its going to be “true”(the check box its going to be marked) so later this option its not going to be visible to a new user, because it was already selected by another user.
This is my code to register the data of the users (ignore the other fields like name and email)
$w.onReady( function () {
$w(“#Registro”).onClick((event) => {
console.log(“Button was clicked”);
if ($w(“#Email”).valid && $w(“#Name”).valid && $w(“#LastName”).valid && $w(“#Country”).valid && $w(“#Idiom”).valid && $w(“#Comite”).valid && $w(“#PaisComite”).valid) {
let email = $w(“#Email”).value;
let name = $w(“#Name”).value;
let lastname = $w(“#LastName”).value;
let country = $w(“#country”).value;
let idiom = $w(“#Idiom”).value;
let comite = $w(“#Comite”).value;
let paisComite = $w(“#PaisComite”).value;//Here is where I save the what the user choosed in the second dropdown
wixUsers.register(email, {
contactInfo: {
“email”: email,
“name”: name
}
})
.then((result) => {
$w(“#DelegadosIndividuales”).save()
.then((item) => {
wixLocation.to(“/HOME”);
})
Notice that I use 2 databases, one to register the user input with is: “DelegadosIndividuales” and another that contains the options for the Dropdowns: “ComiteyPais” (This is not relevant, just to let you know how my project is structured)
Basically what I need its code that: when the button submitted its clicked, the corresponding row in the field “status” to the selected country by the user its placed as “true” (this means that in my database the field at the right of the selected country is placed as true). I know there is a function “SetFieldValueAs” but I think there is something missing for what I need to do, because I don’t want to put all my status columns as true, but only the row that is next to the country that the user selected!
This is a gif of what I precisely want to automatice when the user chooses a country and clicks the submit button (In this example lets say that the user chooses USA, so the code automatically sets the field next to that country as “true”)
Thank you for all your kind help!
Any question or more information just let me know!