Hi I am submitting data to a collection (with a rich text editor) and I have a .gif file I want to show that says 'saving' as soon as you press submit. However, when I put it in the code eg. $w("#group24").show(); to show this element I have to press submit twice to save the information??
SITE URL: https://pete092.wixsite.com/book-the-best/add-property
Code:
import wixWindow from 'wix-window';
import wixData from 'wix-data';
export function submit_click(event, $w) {
$w("#group24").show();
//Send a blank message to the HTML element. This tells the HTML
//element you want it to send you its contents
$w("#html1").postMessage(" ");
//Receive the message from the HTML element
$w("#html1").onMessage((event) => {
//Set the value for the rich text field of the dataset's
//current item to be the data in the HTML element
$w("#dataset2").setFieldValue("longDescription", event.data);
//Submit the current item of the dataset
$w("#dataset2").save()
.then((res) => {
console.log("saving", res);
$w("#group24").show();
setTimeout(function(){$w("#group24").hide(); }, 2100);
wixWindow.openLightbox('SAVED')
.then((data) => {
$w("#html1").postMessage("x", data);
});
$w("#PropertyInfo").value = null;
$w("#Location").selectedIndex = undefined;
});
});
}
It was an async problem. The save() was executing before all of the rich text fields were populated, so some would save and others wouldn't. I got it to work after moving the save() inside the last onMessage(). I wish I better understood when to use async methods (then, await, ...). Right now, I code "normally" then use other ways when I get erratic results.
$w("#html5").onMessage((event) => {
//Set the value for the rich text field of the dataset's
//current item to be the data in the HTML element
$w("#dataset1").setFieldValue("considerations", event.data);
//save the entire record after the last field is done reading (hopefully)
$w("#dataset1").save();
});
Any solution to this? I'm having a similar problem on a page with multiple rich text fields and other fields. Have to press the button twice to get it to save fully. Also, the 'save successful' text only shows up the second time - nothing shows the first time. I'm going to try to automate the 'double-save', but it would be nice to know why it's happening.