I am trying (and failing) to update a field value in a Collection when a user clicks a button on an item in a repeater tied to that collection. I am able to update the text shown in the item in that repeater but am struggling to get the actual value in the Collection updated. This is my first day using Wix (although not my first day of coding) so pardon my ignorance.
Example:
I have collection:
JobTitle,Status
Job 1,Available
Job 2,Available
Job 3,Available
These are displayed in a repeater and there is a Request button on each row. I want the Request button to change the text of the button (Request) to “Pending”. The item in the Collection should also have it’s status updated to Pending (instead of “Available”). The code below also adds the ability to set it back to “Available” if it was previously changed to “Pending”.
I tried this code:
$w("#button2").onClick((event) => {
let $item = $w.at(event.context)
let status = $item("#text32").text
if (status == "Available") {
$item("#button2").label = "Pending" // Update button label, works great
$w("Jobs11").setFieldValue('Status', "Pending"); // !!! Doesn't seem to work
} else {
$item("#button2").label = "Request" // Update button label, works great
$w("Jobs11").setFieldValue('Status', "Available"); // !! Doesn't seem to work
}
$w("Jobs11").Save(); // Do this to commit the setFieldValue actions above
})
The button labels change but the Collection doesn’t seem to be updated. I preview the page, click the Request button so it changes to Pending, exit out of Preview, bring up the Collection, and it still shows Available.
I’m a bit wary of the $w(“Jobs11”) code. Seems like I’d want to setFieldValue on the specific $item, but I’m stealing code (from the Wix documentation).
Ideas?
Ross is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.