I am working with a client and need to save some extra information alongside the custom form that they are using.
I have been following a tutorial on how to do this and have hit 2 problems.
Firstly, the text box that I am using to show the validation message doesn’t show.
Secondly, I don’t know where to add the onBeforeSave function to save the additional information.
Here’s the code:
import wixData from 'wix-data';
$w.onReady(function () {
});
function validation() {
let validationMessage = "";
if ($w("#input2").valid && $w("#input3").valid) {
saveProperties(); {
}
} else {
if (!$w("#input2").valid) {
validationMessage += "Please enter a Business Name.\n"
}
if (!$w("#input3").valid) {
validationMessage += "Please enter a Business Name.\n"
}
$w("#textErr").text = validationMessage
$w("#textErr").show().then(() => {
$w("#input2, #input3").updateValidityIndication()
})
}
}
function saveProperties() {
$w('#buttonSubmit').disable()
let toInsert = {
"businessName": $w("#input2").value,
"businessEmail": $w("#input3").value,
};
wixData.insert("Properties", toInsert)
.then ((results) => {
let item = results;
console.log(item);
$w("#textErr").text = "Your information has been submitted"
$w("#textErr").show().then(() => {
clearAllElements()
$w("#buttonSubmit").enable()
setTimeout(() => {
$w("#textErr").hide()
}, 5000
)
})
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg)
});
}
function clearAllElements() {
$w('#input2').value = null;
$w('#input2').resetValidityIndication();
}
export function buttonSubmit_click(event) {
validation()
}