console.log = function () {}; // Restrict special characters in address fields function restrictSpecialCharactersFromAddressFields(fieldIds) { const allowedCharsRegex = /^[A-Za-zÀ-ÿ0-9 \-]$/; // Single char match const processedFields = new Set(); fieldIds.forEach(id => { const input = document.getElementById(id); if (!input || processedFields.has(id)) return; // Skip if already processed processedFields.add(id); input.addEventListener('input', function () { let cleanValue = ''; for (let char of this.value) { if (allowedCharsRegex.test(char)) { cleanValue += char; } } this.value = cleanValue; }); }); } // Function to hide field & set language function processFormLanguageField() { const el = $('#gompp_formlanguage'); if (el.length) { // Hide the form language field container el.parent().parent().parent().hide(); // Detect language (fr or en) var lang = document.documentElement.lang.toLowerCase().includes('fr') ? 'French' : 'English'; // Set the hidden field value el.val(lang); return true; } return false; } // Watch the DOM for the language field const languageObserver = new MutationObserver(function (mutations, obs) { if (processFormLanguageField()) { obs.disconnect(); // Stop watching once found and processed } }); languageObserver.observe(document.body, { childList: true, subtree: true }); // Watch the DOM for address fields const addressObserver = new MutationObserver(function () { restrictSpecialCharactersFromAddressFields([ 'gompp_apartmentunitnumber', 'gompp_streetaddress', 'gompp_city', 'gompp_mailingapartmentnumber', 'gompp_mailingstreetaddress', 'gompp_mailingcity', 'gompp_mailingapartmentunitnumber', 'gompp_newapartmentunitnumber', 'gompp_newstreetaddress', 'gompp_newcity', 'gompp_newmailingapartmentunitnumber', 'gompp_newmailingstreetaddress', 'gompp_newmailingcity', 'gompp_newmailingapartmentnumber', 'gompp_temporaryapartmentunitnumber', 'gompp_temporarystreetaddress', 'gompp_temporarycity', 'gompp_currentstreetaddress', 'gompp_previouscity' ]); }); addressObserver.observe(document.body, { childList: true, subtree: true });