Question:
Dynamic Tables (CMS) combinds Choises of two or more radiobuttons
Product:
Wix Editor
What are you trying to achieve:
Hello folks. I would like to ensure that when two or more radio buttons are selected, a single CMS table is filled.
the first question. Is this even possible in wix?
So far I have only managed to transfer the selection from a radio button, see code from another page. If I could get this one, that would be the best.
For explanation you can see what the user can select in the appendix below. Currently selection in 2 radio buttons.
After selecting both and submit, the table should be filled correctly in the sense of an index, depending on the “hit”. For further explanation, the second picture. You can see how I set it up in the cms
What have you already tried:
i’ve tried many codes, but non of this worked
Code for one radiobutton:
import wixData from ‘wix-data’;
$w.onReady(function () {
$w(“#submitButton”).onClick(() => {
let selectedValue = $w(“#radioGroup1”).value;
wixData.query("reviews")
.find()
.then((results) => {
if (results.items.length > 0) {
let item = results.items[0]; // Takes the first (and only) entry in the database
//Update the corresponding rating based on the selection
if (selectedValue === "perfect") {
item.perfect = (item.perfect || 0) + 1;
} else if (selectedValue === "verygood") {
item.verygood= (item.verygood || 0) + 1;
} else if (selectedValue === "okay") {
item.okay = (item.okay || 0) + 1;
}
// Save the updated data to the database
wixData.update("reviews", item)
.then(() => {
console.log("review succesfull");
$w("#text1").text = "Thanks for the review!";
$w("#text1").show();
$w("#Bewertungen").refresh();
})
.catch((err) => {
console.error("error while updating: ", err);
});
} else {
console.error("No Entries found");
}
})
.catch((err) => {
console.error("Issue: ", err);
});
});
});