I’ve updated this post and come as far as I can with the code. (see latest comment below).
I have a survey site that user submit their inspections on. When they submit a new survey I want the status to show either passed or failed icons.
I’ve created a function but I can’t see to find the right place to run it so that the icon refreshes when a new form is submitted.
Please can anyone help?
Thank you
import wixData from 'wix-data';
export function changeFloor_click(event) {
if ($w('#floorMenu').hidden){
$w('#floorMenu').show();
}
else {$w('#floorMenu').hide();
}
}
$w.onReady(function () {
statusUpdate();
});
export function statusUpdate() {
$w('#bagnallLatest').onReady(() => {
let status = $w('#bagnallLatest').getCurrentItem();
if(status.inspectionResult==='Passed'){
$w('#passTick').show();
} else {
$w('#passTick').hide;
}
});
$w('#bagnallLatest').onReady(() => {
let status = $w('#bagnallLatest').getCurrentItem();
if(status.inspectionResult==='Under repair'){
$w('#underRepair').show();
} else {
$w('#underRepair').hide;
}
});
}
$w.onReady(function () {
$w('#fireGlass').onChange(() => {
if ($w('#fireGlass').value === 'Yes'){
$w('#fireGlass').style.backgroundColor = "#67E65B";
} else if ($w('#fireGlass').value === 'No'){
$w('#fireGlass').style.backgroundColor = "#FF4040";
}
});
$w('#iStrip').onChange(() => {
if ($w('#iStrip').value === 'Yes'){
$w('#iStrip').style.backgroundColor = "#67E65B";
} else if ($w('#iStrip').value === 'No'){
$w('#iStrip').style.backgroundColor = "#FF4040";
}
});
$w('#doorClose').onChange(() => {
if ($w('#doorClose').value === 'Yes'){
$w('#doorClose').style.backgroundColor = "#67E65B";
} else if ($w('#doorClose').value === 'No'){
$w('#doorClose').style.backgroundColor = "#FF4040";
}
});
$w('#doorGap').onChange(() => {
if ($w('#doorGap').value === 'No'){
$w('#doorGap').style.backgroundColor = "#67E65B";
} else if ($w('#doorGap').value === 'Yes'){
$w('#doorGap').style.backgroundColor = "#FF4040";
}
});
$w('#fireDoor').onChange(() => {
if ($w('#fireDoor').value === 'Yes One Side'){
$w('#fireDoor').style.backgroundColor = "#67E65B";
} else if ($w('#fireDoor').value === 'No'){
$w('#fireDoor').style.backgroundColor = "#FF4040";
}
});
$w('#fireDoor').onChange(() => {
if ($w('#fireDoor').value === 'Yes Both Sides'){
$w('#fireDoor').style.backgroundColor = "#67E65B";
} else if ($w('#fireDoor').value === 'No'){
$w('#fireDoor').style.backgroundColor = "#FF4040";
}
});
$w('#doorDamage').onChange(() => {
if ($w('#doorDamage').value === 'No'){
$w('#doorDamage').style.backgroundColor = "#67E65B";
} else if ($w('#doorDamage').value === 'Yes'){
$w('#doorDamage').style.backgroundColor = "#FF4040";
}
});
$w('#inspectionResult').onChange(() => {
if ($w('#inspectionResult').value === 'Passed'){
$w('#inspectionResult').style.backgroundColor = "#67E65B";
} else if ($w('#inspectionResult').value === 'Under repair'){
$w('#inspectionResult').style.backgroundColor = "#FF4040";
}
});
$w('#btnSubmit').onClick(() => {
if (validateForm()) {
submitForm();
} else {
updateFormValidation();
}
});
function validateForm() {
return $w('#doorNo').valid &&
$w('#surveyDate').valid &&
$w('#fireGlass').valid &&
$w('#iStrip').valid &&
$w('#doorClose').valid &&
$w('#doorGap').valid &&
$w('#fireDoor').valid &&
$w('#doorDamage').valid &&
$w('#failNotes').valid &&
$w('#inspectionResult').valid;
}
function updateFormValidation() {
$w('#doorNo').updateValidityIndication();
$w('#surveyDate').updateValidityIndication();
$w('#fireGlass').updateValidityIndication();
$w('#iStrip').updateValidityIndication();
$w('#doorClose').updateValidityIndication();
$w('#doorGap').updateValidityIndication();
$w('#fireDoor').updateValidityIndication();
$w('#doorDamage').updateValidityIndication();
$w('#failNotes').updateValidityIndication();
$w('#inspectionResult').updateValidityIndication();
}
function submitForm() {
const formData = {
doorNumber: $w('#doorNo').value,
surveyDate: $w('#surveyDate').value,
fireGlassPanel: $w('#fireGlass').value,
intumescentStrip: $w('#iStrip').value,
doorCloses: $w('#doorClose').value,
doorGapOver4Mm: $w('#doorGap').value,
fireDoorSign: $w('#fireDoor').value,
damageToFireDoor: $w('#doorDamage').value,
failureNotes: $w('#failNotes').value,
inspectionResult: $w('#inspectionResult').value,
};
$w('#successMessage').hide();
$w('#errorMessage').hide();
wixData.insert('Bagnall', formData).then(() => {
$w('#successMessage').show();
$w('#formDoneNext').show();
}).catch(() => {
$w('#errorMessage').show();
}).then (() => {
$w("#bagnallLatest").refresh();
});
}
});
