Hi!
I’m trying to show a loading screen (lightbox) after the user submits a form, before being redirected to his submission page, on my website.
I have managed to do that, only if the user forgets to fill in an input, the database returns an error, and can’t submit the content. So far nothing wrong. But I want the loading screen (lightbox) to automatically close so the user can fill the missing inputs.
Basically I need a piece of code that would say "on submission button click = display loading screen; if database returns an error = loading screen hide;
Here’s my code so far.
import wixData from "wix-data";
import wixWindow from 'wix-window';
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
$w.onReady(function () {
$w("#dataset1").onReady(() => {
const msg = $w("#dataset1").getCurrentItem();
$w("#html1").onMessage((event) => {
if (event.data === "ready") {
$w("#html1").postMessage(msg.longDescription);
//sends out an email when deal is posted
$w("#dataset1").onAfterSave(sendFormData);
}
});
$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
const dataWithFixedLinkStyles = event.data.replace(/\<a/g, `<a style="color:#006bd7; text-decoration: underline;"`);
$w('#dataset1').setFieldValue("descriptionDeal", dataWithFixedLinkStyles)
.then((res) => {
$w("#dataset1").save();
//shows loading screen upon submitting content
wixWindow.openLightbox("Chargement");
});
});
});
});
export function button15_click_1(event, $w) {
//Send a blank message to the HTML element. This tells the HTML
//element you want it to send you its contents
$w("#html1").postMessage("save");
//Receive the message from the HTML element
}
Thanks!