How to send to the collection not the value of the selected tag, but the name of the selected tag.
Im using Wix Studio Editor.
I have a calculator, and I want that after the calculation is completed, when the button is pressed, the data is sent to the collection. Everything is ok with text fields, but with the drop-down list and tags there is a problem. A number (the value of a tag or a drop-down list item) gets into the collection, but the NAME needs to be sent.
This needs to be done for 3 fields. The calculation code looks like this.
$w('#Design').onChange((event) => {
const selectedTag = $w('#Design').value;
let selectedIndex = Number($w('#Design').selectedIndices);
calculator();
for (var i = 0; i < selectedTag.length - 1; i++) {
if (selectedTag.length > 1) {
selectedTag.shift();
}
}
setTimeout(() => {
$w('#Design').value = [];
$w('#Design').value = selectedTag;
for (selectedIndex = 0; selectedIndex < selectedTag.length; selectedIndex++) {
if (selectedTag[selectedIndex] === "0") {
selectedTag.splice(selectedIndex, 1, "Власний дизайн")
} else if (selectedTag[selectedIndex] === "300") {
selectedTag.splice(selectedIndex, 1, "Дизайн відсутній")
}
$w('#quoteSummaryText').text = `🧹 ${selectedTag.toString()}`;
}
calculator();
}, 1)
});
During the calculation process, it displays both the name and value of the tag in the text field, as planned, but I only want to send only the NAME of the selected tag to the collection.
HELP, IM TILTED!
**
Yeeeeeeah, im already done with it!
**
It worked, but only for 1 element. All that remains is to force the data from the drop-down list and another field with tags to be sent to the collection. How can I put everything in one place in the code?
$w("#paymentButton").onClick(() => {
const selectedTag = $w('#Design').value
var design = $w("#Design").value
let selectedIndex = Number($w('#Design').selectedIndices);
for (selectedIndex = 0; selectedIndex < selectedTag.length; selectedIndex++) {
if (selectedTag[selectedIndex] === "0") {
selectedTag.splice(selectedIndex, 1, "Власний дизайн")
} else if (selectedTag[selectedIndex] === "300") {
selectedTag.splice(selectedIndex, 1, "Дизайн відсутній")
}
let toInsert = {
"designOptions": selectedTag.splice(selectedIndex, 1)
}
wixData.insert("websiteWanted", toInsert)
}
})
Remembering that initially the data ends up in the fields that are displayed to the site visitor, I decided to take it from there and add it to the collection. everything was much simpler than it seemed.
$w("#paymentButton").onClick(() => {
var design = $w('#quoteSummaryText').text
var siteType = $w('#text82').text
var numberPages = $w('#numberPages').value
var phoneNumber = $w('#input1').value
var name = $w('#input2').value
var delivery = $w('#text84').text
let toInsert = {
"designOptions": $w('#quoteSummaryText').text,
"siteType": $w('#text82').text,
"numberPages": $w('#numberPages').value,
"phoneNumber": $w('#input1').value,
"title": $w('#input2').value,
"timeFor": $w('#text84').text
}
wixData.insert("websiteWanted", toInsert)
})