Hi,
I can use some help with some custom on-click code.
I am not a coder and still trying to figure things out by copying code parts from Q&A of other users.
What I am trying to do:
I have a page with a “repeater” that is connected to a collection called “offers”.
The page also has members dataset connected.
I am trying to set the button on the repeater to do the following:
1.
Fetch the user email (from the members collection) and offer title (from the offers collection) and place it into a third collection (users_offers) creating a new row.
2.
Link to a dynamic page based on “users_offers” (I am using the unique ID in the users_offers collection in order to create the URL.
So, the dynamic page is actually based on a collection row that is created upon clicking the button that links to it.
Where I got so far:
1.
I managed to come up with the following code that works partially but only on “preview mode” and not at all on the live website (even after publishing the changes).
On preview mode it fetches my email and “offer title” of the first item in the repeater regardless of the offer I click on (always the same value).
import wixData from 'wix-data';
export function button4_click(event) {
let title = $w("#dataset2").getCurrentItem(title);
let loginEmail = $w("#dataset1").getCurrentItem(loginEmail);
let toInsert = {
"user_id": loginEmail,
"offer_id": title,
};
let options = {
"suppressAuth": true,
"suppressHooks": true
};
wixData.insert("Users_Offers", toInsert, options)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
I built the dynamic page and linked it to the button but nothing happens when I click on it.
Thanks in advance.