Before user clicks “Buy now” button (which is a default PayPal button), I would like to collect user’s email address with a User Input text box.
Problem is that there is no “Submit” button on this page. How to update the record/data collection’s email address for the latest item?
I had a try to update the email address in below function. It seems this function is not been called.
export function inEmailAddr_change(event, $w) {
// Find the latest user input and update the email address.
wixData.query(“UserInputs”)
.limit(1)
.find()
.then( (results) => {
if (results.items.length > 0)
{
let item = results.items[0];
item.dbcEmail = $w(‘#input1’).text; // a user input box will be added to update email.
wixData.update(“UserInputs”, item);
}
} )
. catch ( (err) => {
let errorMsg = err;
} );
}
Are you using a dataset on this page? If so, the following code (with names changed as needed), placed in the blur event of the input or perhaps in the mousein event of the PayPal button, would write the data just for that field.
Hi Anthony,
Thank you for the quick help.
The issue has been resolved by recreating a onChange function with the user input text box. Then the newly created onChange function is called.
My original code above works fine with one modification with your hint:
Change from: item.dbcEmail = $w(’ #input1 ‘).text;
to: item.dbcEmail = $w(’#input1’).value;
Below is the complete code:
export function input1_change(event) {
// Find the latest user input and update the email address.
wixData.query(“UserInputs”)
.limit(1)
.find()
.then( (results) => {
if (results.items.length > 0)
{
let item = results.items[0];
item.dbcEmail = $w(‘#input1’).value; // updated email address
wixData.update(“UserInputs”, item);
}
} )
. catch ( (err) => {
let errorMsg = err;
} );
}