I am using code as opposed to connectors because I need client details to be inserted into the DB without requiring the client to type them into a form. I currently have two upload buttons that are coded to add files into a DB. Currently, both #clientUpload1 and #clientUpload2 are successfully adding files into the DB. However, when there is no file being uploaded, the submit button will not function.
QUESTION: What changes need to be made to my code to “unrequire” #clientUpload1 UNLESS it is triggered?
-
#clientUpload1 is not hidden on load, but should only be required if certain parameters are met, otherwise it should be visible but NOT required.
-
#clientUpload2 IS hidden on load and should be required when triggered.
export function clientUpload1_change(event) {
let file = $w("#clientUpload1").value[0].name;
$w("#fileTitle1").text= String(file);
}
export function clientUpload2_change(event) {
let file = $w("#clientUpload2").value[0].name;
$w("#fileTitle2").text= String(file);//Add your code for this event here:
}
export function buttonSubmitGo_click() {
if($w("#clientUpload1").value.length > 0) {
$w("#buttonSubmitGo").disable();
$w("#buttonSubmitGo").label = 'Please wait...';
$w("#clientUpload1").startUpload()
.then( (uploadedFile) => {
let fileLocation = uploadedFile.url;
insertData(fileLocation);
});
} else {
$w("#buttonSubmitGo").enable();
$w("#buttonSubmitGo").label = 'Submit';
}
}
function insertData(fileLocation) {
let toInsert = {
"clientUpload1": fileLocation,
"fileTitle1": $w("#fileTitle1").text,
"fileTitle2": $w("#fileTitle2").text,
"clientUpload2": fileLocation,
"clientId": $w("#clientId").value, //clientId,
"email": $w("#email").value, //userEmail,
"fullName": $w("#fullName").value,
"projectType": $w("#projectType").value,
"projectCategory": $w("#category").value,
"planType": $w("#planType").value,
"projectTitle": $w("#projectTitle").value,
"projectDetails": $w("#projectDetails").value,
"projectStatus": $w("#projectStatus").value
};
wixData.insert("Projects", toInsert)
.then(() => {
wixLocation.to("/success");
});
}