Before Save validation
Posted: Mon Oct 06, 2025 5:10 pm
I would like to before saving my vehiclein form (field reg_no} to check that a record in vehiclestk (field stk_reg_no) doesn't already exist with the same reg_no and if it does the record should not be saved and an Alert is shown saying 'Duplicate Reg No not allowed'.
I already check following with js in browse and edit:
Is there a way I can add this to the above or should I run a php query to do a count in Before Save? with a nuDisplayError if the count is not equal to 0?
I already check following with js in browse and edit:
Code: Select all
window.nuBeforeSave = function() {
var vehicleType = nuGetValue("vehicle_select"); // Get value from the "vehicle_select" field
var trlContainerNo = nuGetValue("trl_container_no").trim(); // Get value from "trl_container_no"
if ((vehicleType === "Truck & Trailer" || vehicleType === "Truck & Container") && trlContainerNo === "") {
alert("Trailer/Container Number is required when selecting 'Truck & Trailer' or 'Truck & Container'");
return false;
}
if ((vehicleType === "Truck Only" || vehicleType === "Car") && trlContainerNo !== "") {
alert("Trailer/Container Number must be blank for 'Truck Only' or 'Car'.");
return false;
}
return true; // Allows form save if all conditions are met
};