// Detect LANGUAGES (EN/FR) const LANGUAGES = document.documentElement.lang.toLowerCase().includes("fr") ? "fr" : "en"; // Localized error messages const fileNameFieldErrorMessages = { filename: { en: "File name is too long. Maximum 55 characters allowed.", fr: "Le nom du fichier est trop long. Maximum de 55 caractères autorisés." } }; // Create validator for file name length function createFileNameValidator(fieldId, errorMessageKey, maxLength = 55) { var validator = document.createElement("span"); validator.style.display = "none"; validator.id = fieldId + "FileNameValidator"; validator.controltovalidate = fieldId; validator.errormessage = "" + fileNameFieldErrorMessages[errorMessageKey][LANGUAGES] + ""; validator.validationGroup = ""; validator.initialvalue = ""; validator.evaluationfunction = function () { var fileName = $("#" + fieldId + "hidden_filename").val(); if (!fileName) return true; // No file uploaded return fileName.length <= maxLength; }; Page_Validators.push(validator); } // Ensure Page_Validators exists if (typeof Page_Validators === "undefined") { var Page_Validators = []; } const fileFieldsToValidate = [ "gompp_supportingdoc1", "gompp_signaturedocument", "gompp_signaturedocument2", "gompp_supportingdocument", "gompp_supportingdocument2", "gompp_completedbyrelationshiptoapplicantdoc2", "gompp_completedbyrelationshiptoapplicantdoc1", "gompp_supportingdocument1", "gompp_supportingdocument3", "gompp_supportingdocument4", "gompp_divorcecertificateseparationagreement", "gompp_supportingdoc1", "gompp_copyofdndcard", "gompp_copyofdndcard2","gompp_spouseofaregularforcememberdoc1","gompp_spouseofaregularforcememberdoc2","gompp_marriagecertificate","gompp_commonlawdocument4", "gompp_commonlawdocument3","gompp_commonlawdocument2","gompp_commonlawdocument1","gompp_residencysupportingdocuments","gompp_residencysupportingdocuments2","gompp_residencysupportingdocuments3","gompp_residencysupportingdocuments4", "gompp_canadianbirthcertificate","gompp_refugeesupportingdocument","gompp_permitholderclergyvisitorrecordwpermit","gompp_permitholderclergychurchletter","gompp_permitholderworkpermitworkpermit","gompp_permitholderworkpermitsawpdocument", "gompp_permitholderworkpermitsawpproofofemploy","gompp_permitholderstudystudypermit","gompp_permitholderstudyenrollmentletter","gompp_permitholderdiplomatsupportingdocument","gompp_permitholderdiplomatemploymentdocument","gompp_visitorrecordsupportingdocument", "gompp_visitorrecordproofofarrival","gompp_permanentresidencycard","gompp_permanentresidencysupportingdoc2","gompp_releaseorretirementpaperworkmilitary","gompp_cancellationletterfromoriginatingprovince","gompp_birthcertificatefordependent","gompp_proxysupportingdocument","gompp_proxysupportingdocument2","gompp_proxysupportingdocument3","gompp_proxysupportingdocument4" ]; // Run once after DOM is ready document.addEventListener("DOMContentLoaded", () => { fileFieldsToValidate.forEach(fieldId => { if (document.getElementById(fieldId)) { createFileNameValidator(fieldId, "filename", 55); } }); });