kilvalidate 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kilnextvalidation.js +19 -3
- package/kilnextvalidation.min.js +1 -1
- package/kilvish.min.js +1 -1
- package/package.json +1 -1
package/kilnextvalidation.js
CHANGED
|
@@ -699,7 +699,20 @@ function validateKilvishInput(event) {
|
|
|
699
699
|
|
|
700
700
|
// --- General valid character sets
|
|
701
701
|
let validCharacters = /^[a-zA-Z\s]*$/; // only char, no special char no numbers
|
|
702
|
-
|
|
702
|
+
const hasExplicitKilvishRule =
|
|
703
|
+
inputField.hasAttribute('data-kilvish-num') ||
|
|
704
|
+
inputField.hasAttribute('data-kilvish-num11') ||
|
|
705
|
+
inputField.hasAttribute('data-kilvish-char') ||
|
|
706
|
+
inputField.hasAttribute('data-kilvish-amount') ||
|
|
707
|
+
inputField.hasAttribute('data-kilvish-date') ||
|
|
708
|
+
inputField.hasAttribute('data-kilvish-dategroup') ||
|
|
709
|
+
inputField.hasAttribute('data-kilvish-age') ||
|
|
710
|
+
inputField.hasAttribute('data-kilvish-file') ||
|
|
711
|
+
inputField.hasAttribute('data-kilvish-password');
|
|
712
|
+
const allowDefaultRules =
|
|
713
|
+
inputField.hasAttribute('data-kilvish-default') ||
|
|
714
|
+
(inputField.form && inputField.form.hasAttribute('data-kilvish-default'));
|
|
715
|
+
let hasValidationRule = allowDefaultRules;
|
|
703
716
|
|
|
704
717
|
// Define allowed image/file types
|
|
705
718
|
const validFilesTypes = {
|
|
@@ -720,8 +733,11 @@ function validateKilvishInput(event) {
|
|
|
720
733
|
only_doc_image: 'Document & Image'
|
|
721
734
|
};
|
|
722
735
|
|
|
723
|
-
// --- class-agnostic cleanup (no container lookups)
|
|
724
|
-
clearFieldError(inputField);
|
|
736
|
+
// --- class-agnostic cleanup (no container lookups)
|
|
737
|
+
clearFieldError(inputField);
|
|
738
|
+
if (!hasExplicitKilvishRule && !allowDefaultRules) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
725
741
|
|
|
726
742
|
// --- Custom validations by field/name/type
|
|
727
743
|
if (inputField.name === 'description' || inputField.name === 'address') {
|
package/kilnextvalidation.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! kilvalidate | Author: Kilvish (Vasu Birla) | MIT */
|
|
2
|
-
!function(e,t){"object"==typeof module&&module.exports?module.exports=t(e):"function"==typeof define&&define.amd?define((function(){return t(e)})):e&&(e.kilvalidate=t(e))}("undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:void 0,(function(e){if(!e||!e.document){const e=()=>{},t=()=>!1;return{validateRequiredFields:t,addRealTimeValidation:e,validateForm:t,addAsteriskToRequiredFields:e,attachInputEvents:e,addValidateFormToSubmitButtons:e,validateKilvishInput:e,addErrorMessage:e,init:e,initPasswordStrengthMeter:e}}const t=e.document;!function(){if(t.getElementById("kil-error-style"))return;const e=t.createElement("style");e.id="kil-error-style",e.textContent="\n .error-message {\n display:block;\n min-height:16px; /* reserves space even when empty */\n margin-top:4px;\n font-size:12px;\n color:#d32f2f;\n line-height:1.25;\n opacity:1;\n transition: opacity .12s ease;\n }\n .error-message.is-hidden{ opacity:0; }\n ",t.head.appendChild(e)}();const a=t=>e.CSS&&"function"==typeof e.CSS.escape?e.CSS.escape(String(t)):String(t).replace(/["\\]/g,"\\$&");function r(e){if(!e)return null;if(e.tagName&&"FORM"===String(e.tagName).toUpperCase())return e;if("string"==typeof e){return/^[#.\[]/.test(e)||e.includes(" ")||e.includes("[")?t.querySelector(e):t.getElementById(e)||t.querySelector(e)}return e.querySelector?e:null}function n(e){if(!e)return null;const r=e.form||t;let n=null;if(e.id&&(n=r.querySelector(`label[for="${a(e.id)}"]`)),!n&&e.name&&(n=r.querySelector(`label[for="${a(e.name)}"]`)),n||(n=e.closest("label")),!n){const t=e.closest("fieldset");t&&(n=t.querySelector("legend"))}return n}function l(e){const a=n(e);if(!a)return;let r=a.querySelector(".kil-required-star");r||(r=t.createElement("span"),r.className="kil-required-star",r.textContent=" *",a.appendChild(r)),r.style.visibility="visible"}function s(e){const t=n(e);if(!t)return;const a=t.querySelector(".kil-required-star");a&&(a.style.visibility="hidden")}function i(e){const t=r(e);if(!t)return console.warn("Form not found for validation:",e),!1;const a=t.querySelectorAll("input[required], select[required], textarea[required]"),n=(t.querySelectorAll("fieldset.radios"),t.querySelectorAll('input[type="radio"]')),l={},s=new Set;t.querySelectorAll('input[type="checkbox"]').forEach((e=>{const t=e.name;l[t]||(l[t]=[]),l[t].push(e),e.hasAttribute("required")&&s.add(t)}));t.querySelectorAll(".select2");let i=!0,o="This Field is Required.";if(t.querySelectorAll(".error-message").forEach((e=>{e.textContent="",e.classList.add("is-hidden")})),a.forEach((e=>{e.style.border=""})),a.forEach((e=>{const t=e.closest(".form-group")||e.parentNode;e.parentNode;if("date"==e.type){o="Please Select Date",e.style.border="";e.value.trim()||(i=!1,e.style.border="1px solid red",b(t,o))}else o="comments"==e.name?"Please Enter Comments":"email"==e.type?"Please Enter Email":"password"==e.type?"Please Enter Password":"This Field is Required.";const a=e.getAttribute("data-kilvish-name");let r;if(o=`${a||"This"} Field is Required.`,("tel"===e.type||e.hasAttribute("data-kilvish-tel"))&&(r=function(e){const t=e.closest(".kiltel-phone-wrap")||e.parentElement,a=t&&(t.querySelector('input[name="contact"]')||t.querySelector("#contact"));if(a)return(a.value||"").replace(/\D/g,"").length<7;const r=(e.value||"").trim().replace(/\s|-/g,"");return!r||(!!/^\+?$/.test(r)||(!!/^\+?\d{1,4}$/.test(r)||r.replace(/\D/g,"").length<7))}(e),r&&(o=`${a||"Phone"} is required (enter full number, not just country code).`)),r)return i=!1,e.style.border="1px solid red",void b(e,o);e.value.trim()||(i=!1,e.style.border="1px solid red",b(t,o))})),n.length>0){const e={};n.forEach((t=>{const a=t.name;e[a]||(e[a]={isSelected:!1,groupElement:t.closest(".form-group")||t.closest(".mb-3")||t.closest(".form-check")||t.closest(".radios")||t.closest(".col-md-6")}),t.checked&&(e[a].isSelected=!0)})),Object.entries(e).forEach((([e,t])=>{if(!t.isSelected){i=!1;const a="Please select one option.";if(!t.groupElement)return void console.error("Invalid group element for radio group:",e);b(t.groupElement,a)}}))}return Object.keys(l).forEach((e=>{const t=l[e];if(t.some((e=>e.hasAttribute("data-ignore-kilvish"))))return;if(!t.some((e=>e.checked))){i=!1;const a=s.has(e)?"Please check this box to proceed":"Please select at least one option.";b(t[0].closest(".form-group")||t[0].closest(".form-check")||t[0].closest(".checkbox-container")||t[0].closest(".some-other-container"),a)}})),i}function o(e){const t=r(e);if(!t)return;const a=t.querySelectorAll("input[required], select[required], textarea[required]"),n=(e,t=!0)=>{t?l(e):s(e)};function i(e){const t=e.form||e.closest("form");if(!t)return;const a=e.nextElementSibling;let r=e,n="afterend",l=e.name||e.id||"field";"SELECT"===e.tagName&&a&&(a.classList.contains("select2")||a.classList.contains("select2-container"))?(r=a,n="afterend",l=e.name||e.id||"select"):e.parentElement&&e.parentElement.classList.contains("input-group")&&(r=e.parentElement,n="afterend",l=e.name||e.id||"inputgroup");const i=t.querySelector(`#kil_err_${String(l).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);i&&(i.textContent="",i.classList.add("is-hidden")),e.style.border="",s(e)}a.forEach((e=>{if("1"===e.dataset.kilRealtimeBound)return;const t=()=>{e.value.trim()?(i(e),n(e,!1)):n(e,!0)};e.addEventListener("input",t),e.addEventListener("change",t),e.dataset.kilRealtimeBound="1"}));const o=t.querySelectorAll('input[type="radio"]');[...new Set(Array.from(o).map((e=>e.name)))].forEach((e=>{const a=t.querySelectorAll(`input[type="radio"][name="${e}"]`);a.forEach((e=>{"1"!==e.dataset.kilRadioBound&&(e.addEventListener("change",(()=>{Array.from(a).some((e=>e.checked))&&i(e)})),e.dataset.kilRadioBound="1")}))}));const d=t.querySelectorAll('input[type="checkbox"]');[...new Set(Array.from(d).map((e=>e.name)))].forEach((e=>{const a=t.querySelectorAll(`input[type="checkbox"][name="${e}"]`);a.forEach((e=>{"1"!==e.dataset.kilCheckboxBound&&(e.addEventListener("change",(()=>{Array.from(a).some((e=>e.checked))&&i(e)})),e.dataset.kilCheckboxBound="1")}))}))}function d(t,a){const r=i(t);if(!r){const t=a||e.event;t&&t.preventDefault&&t.preventDefault()}return r}function c(e=t){e.querySelectorAll("label, legend").forEach((e=>{e.querySelectorAll("span").forEach((e=>{e.classList.contains("kil-required-star")||"*"!==e.textContent.trim()||e.remove()}));const t=e.querySelectorAll(".kil-required-star");for(let e=1;e<t.length;e++)t[e].remove()}))}function u(){t.querySelectorAll("input[required], select[required], textarea[required]").forEach(l)}function p(){t.querySelectorAll("input, select, textarea").forEach((e=>{"1"!==e.dataset.kilInputBound&&(e.hasAttribute("data-ignore-kilvish")||(e.addEventListener("keyup",h),e.addEventListener("change",h),e.dataset.kilInputBound="1"))}))}function m(){t.querySelectorAll("form").forEach((e=>{const t=e.id;"1"!==e.dataset.kilFormSubmitBound&&(e.addEventListener("submit",(t=>d(e,t))),e.dataset.kilFormSubmitBound="1");const a=t?`#${t}`:e;e.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((e=>{"1"!==e.dataset.kilSubmitBound&&(e.addEventListener("click",(e=>d(a,e))),e.dataset.kilSubmitBound="1")}))}))}!function(){if(t.getElementById("kil-req-style"))return;const e=t.createElement("style");e.id="kil-req-style",e.textContent="\n .kil-required-star{ color:#d32f2f; margin-left:2px; }\n .error-message{ display:block; min-height:16px; margin-top:4px; font-size:12px; color:#d32f2f; line-height:1.25; opacity:1; transition:opacity .12s ease; }\n .error-message.is-hidden{ opacity:0; }\n ",t.head.appendChild(e)}();let y=null;function f(){c(),u();t.querySelectorAll("form").forEach((e=>{const t=e.id;o(t||e)})),p(),m(),g(),t.querySelectorAll('input[type="password"]').forEach(x),!y&&e.MutationObserver&&(y=new MutationObserver((e=>{for(const t of e)t.addedNodes&&t.addedNodes.forEach((e=>{e instanceof HTMLElement&&(e.matches&&e.matches('input[type="password"]')&&x(e),e.querySelectorAll&&e.querySelectorAll('input[type="password"]').forEach(x))}))})),y.observe(t.documentElement,{childList:!0,subtree:!0}))}function h(e){const a=e.target;if(a.hasAttribute("data-ignore-kilvish"))return;function r(e){const t=e.form||e.closest("form");if(!t)return;const a=e.nextElementSibling;let r=e.name||e.id||"field";"SELECT"===e.tagName&&a&&(a.classList.contains("select2")||a.classList.contains("select2-container"))?r=e.name||e.id||"select":e.parentElement&&e.parentElement.classList.contains("input-group")&&(r=e.name||e.id||"inputgroup");const n=t.querySelector(`#kil_err_${String(r).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);n&&(n.textContent="",n.classList.add("is-hidden")),e.style.border=""}let n=/^[a-zA-Z\s]*$/,l=!1;const s={image:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],doc:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pdf:["application/pdf"],mix:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],only_pdf_image:["application/pdf","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],only_doc_image:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"]},i={image:"Image",doc:"Document",pdf:"PDF",mix:"Image & Document",only_pdf_image:"PDF & Image",only_doc_image:"Document & Image"};if(r(a),"description"===a.name||"address"===a.name){if(l=!0,n=/^[a-zA-Z0-9@,._\s-'"*]*$/,a.value.length>400)return b(a,"Input exceeds the maximum length of 400 characters!"),a.style.border="1px solid red",void(a.value=a.value.substring(0,400))}else if("firstname"===a.name||"lastname"===a.name||"appointment_by"===a.name){l=!0,n=/^[a-zA-Z\s-]*$/;const t=/^[a-zA-Z0-9._@-\s]+$/,r=a.value;if(t.test(r)&&(r.length>20||r.length<2))return b(a,"This Field Must Be Between 2 And 20 Characters."),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("otp"===a.name){l=!0,n=/^\d{6}$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&6!==r.length)return b(a,"OTP must be exactly 6 digits"),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("number_of_items"===a.name){l=!0,n=/^\d{0,6}(\.\d{0,2})?$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&r.length>3)return b(a,"Pacakge Number Cannot Be Exceed 3 Digits"),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("contact"===a.name||"agent_contact"===a.id||"fullcontact"===a.name)l=!0,n=/^[\d\-\s]{0,20}$/;else if("number"===a.type){l=!0,n=/^\d{0,20}$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&(r.length>20||r.length<1))return b(a,"This Must Be Between 1 And 20 Digits."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("tel"===a.type){l=!0;let t=a.value.trim().replace(/\s+/g,"");a.value=t;if(n=/^\+?\d{7,15}$/,!/^\+?\d{7,15}$/.test(t))return b(a,"Enter a valid phone number (7–15 digits, optional +)."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("kildate"===a.name){l=!0,n=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const t=a.value.trim(),r=new Date(t.replace(/[-\/]/g,"/")),s=new Date;s.setHours(0,0,0,0);const i=a.getAttribute("data-kilvish-date");if(i){const[t,n]=i.replace("_","").split("_").map(Number),l=new Date(s),o=new Date(s);if(l.setFullYear(s.getFullYear()-t),o.setFullYear(s.getFullYear()-n),r>l||r<o)return b(a,`Birthday cannot be less than ${t} years ago or more than ${n} years in the future.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(r<s)return b(a,"The date cannot be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else{if("date"===a.type||"month"===a.type){l=!0,n=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=a.value.trim(),s="month"===a.type?new Date(r+"-01"):new Date(r.replace(/[-\/]/g,"/")),i=new Date;i.setHours(0,0,0,0);const o=a.getAttribute("data-kilvish-date");if(o)if(/^_(\d+)_(\d+)$/.test(o)){const[t,r]=o.replace("_","").split("_").map(Number),n=new Date(i),l=new Date(i);if(n.setFullYear(i.getFullYear()-t),l.setFullYear(i.getFullYear()-r),s>n||s<l)return b(a,`Age must be between ${t} and ${r} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^_(\d+)$/.test(o)){const t=Number(o.replace("_","")),r=new Date(i);if(r.setFullYear(i.getFullYear()-t),s.getTime()!==r.getTime())return b(a,`You must be exactly ${t} years old.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/future/.test(o)){if("future"===o&&s<=i)return b(a,"The selected date must be in the future."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("today_future"===o&&s<i)return b(a,"The selected date cannot be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/(\d+)_days_future/.test(o)){const t=Number(o.match(/(\d+)_days_future/)[1]),r=new Date(i);if(r.setDate(i.getDate()+t),s>r||s<i)return b(a,`The selected date must be within the next ${t} days.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_future$/.test(o)){const t=Number(o.match(/^(\d+)_years_future$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()+t),s<i||s>r)return b(a,`The date must be within the next ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_after$/.test(o)){const t=Number(o.match(/^(\d+)_years_after$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()+t),s.getTime()!==r.getTime())return b(a,`The date must be exactly ${t} years after today.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}else if(/past/.test(o)){if("past"===o&&s>=i)return b(a,"The selected date must be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/^(\d+)_years_past$/.test(o)){const t=Number(o.match(/^(\d+)_years_past$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()-t),s>i||s<r)return b(a,`The date must be within the past ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}else if(/^(\d+)_years_before$/.test(o)){const t=Number(o.match(/^(\d+)_years_before$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()-t),s>=r)return b(a,`The date must be before ${t} years ago.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_after$/.test(o)){const t=Number(o.match(/^(\d+)_years_after$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()+t),s<=r)return b(a,`The date must be after ${t} years from today.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/Between_(\d+)_(\d+)/.test(o)){const[t,r]=o.match(/Between_(\d+)_(\d+)/).slice(1,3).map(Number),n=new Date(t,0,1),l=new Date(r,11,31);if(s<n||s>l)return b(a,`The date must be between ${t} and ${r}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/from_(\d+)/.test(o)){const t=Number(o.match(/from_(\d+)/)[1]);if(s<new Date(t,0,1))return b(a,`The date must be from the year ${t} onwards.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/till_(\d+)/.test(o)){const t=Number(o.match(/till_(\d+)/)[1]);if(s>new Date(t,11,31))return b(a,`The date must be till the year ${t}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else{if("not_today"===o&&s.getTime()===i.getTime())return b(a,"Today's date is not allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("weekday"===o&&(0===s.getDay()||6===s.getDay()))return b(a,"Only weekdays (Monday to Friday) are allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("weekend"===o&&s.getDay()>=1&&s.getDay()<=5)return b(a,"Only weekends (Saturday and Sunday) are allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("first_of_month"===o&&1!==s.getDate())return b(a,"The date must be the first day of the month."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/^exact_(\d+)$/.test(o)){const t=Number(o.match(/^exact_(\d+)$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()-t),s.getTime()!==r.getTime())return b(a,`You must be exactly ${t} years old.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if("last_of_month"===o){const t=new Date(s.getFullYear(),s.getMonth()+1,0).getDate();if(s.getDate()!==t)return b(a,"The date must be the last day of the month."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}const d=a.getAttribute("data-kilvish-dategroup");if(d&&/.+_[12]$/.test(d)){const[r,n]=d.split("_"),l="1"===n?"2":"1",s=t.querySelector(`[data-kilvish-dategroup="${r}_${l}"]`);if(s&&s.value){const t="month"===a.type?new Date(a.value+"-01"):new Date(a.value.replace(/[-\/]/g,"/")),i="month"===s.type?new Date(s.value+"-01"):new Date(s.value.replace(/[-\/]/g,"/"));if(!("1"===n&&t<=i||"2"===n&&t>=i)){const t=a.dataset.kilvishDate_name||`Field (${r}_${n})`,i=s.dataset.kilvishDate_name||`Field (${r}_${l})`;return b(a,`${t} must be ${"1"===n?"before or same as":"after or same as"} ${i}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}}return void(a.style.border="")}if("age"===a.name){l=!0;const t=a.value.trim(),r=parseInt(t,10);if(isNaN(r))return b(a,"Please enter a valid number for age."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));const n=a.getAttribute("data-kilvish-age")||"18";if(/^(\d+)$/.test(n)){const t=Number(n);if(r!==t)return b(a,`Age must be exactly ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_(\d+)$/.test(n)){const[t,l]=n.split("_").map(Number);if(r<t)return b(a,`Minimum age must be ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(r>l)return b(a,`Age cannot exceed ${l} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}return void(a.style.border="")}}if("model_name"===a.name||"models[]"===a.name)l=!0,n=/^[a-zA-Z0-9]{4,20}$/;else if("email"===a.type){l=!0,n=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;const t=/^[a-zA-Z0-9._@-]+$/,r=a.value;if(t.test(r)&&!n.test(r))return b(a,"Invalid Email Format."),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}if(a.hasAttribute("data-kilvish-num")){l=!0;const t=a.value,r=a.getAttribute("data-kilvish-num");n=/^[0-9]*$/;let s=null,i=null;const o=r.match(/^_(\d+)_(\d+)$/);o&&(s=parseInt(o[1],10),i=parseInt(o[2],10));const d=r.match(/^exact_(\d+)$/),c=d?parseInt(d[1],10):null;/^\d*$/.test(t)?null!==c&&t.length!==c?(b(a,`This field must contain exactly ${c} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):s&&t.length<s||i&&t.length>i?(b(a,`This Field Must be between ${s} and ${i} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):a.style.border="":(b(a,"Only numerical characters are allowed."),a.style.border="2px solid red")}if(a.hasAttribute("data-kilvish-num11")){l=!0;const t=a.value,r=a.getAttribute("data-kilvish-num");n=/^[0-9]*$/;let s=null,i=null;const o=r?r.match(/^_(\d+)_(\d+)$/):null;o&&(s=parseInt(o[1],10),i=parseInt(o[2],10)),"exact_20"===r&&(n=/^[0-9]{20}$/),n.test(t)?s&&t.length<s||i&&t.length>i?(b(a,`This Field Must be between ${s} and ${i} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):a.style.border="":(b(a,"exact_20"===r?"This field must contain exactly 20 digits.":"Only numerical characters are allowed."),a.style.border="2px solid red")}if(a.hasAttribute("data-kilvish-char")){l=!0;const t=a.value,r=a.getAttribute("data-kilvish-char");if(r.startsWith("Yes")||r.startsWith("mix")){"mix"===r?n=/^[a-zA-Z0-9]*$/:"Yes"===r&&(n=/^[a-zA-Z]*$/);const l=r.split("_").slice(1).join("");if(l&&(n=new RegExp(`^[a-zA-Z0-9${l}]*$`)),!n.test(t))return b(a,"Invalid character entered!"),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}if(a.hasAttribute("data-kilvish-amount")){l=!0;const r=a.getAttribute("data-kilvish-amount");n=/^\d+(\.\d{0,2})?$/;let s="USD",i=null,o=null;const d=r.match(/^([A-Z]{3})(?:_(\d+)_(\d+))?$/);d&&(s=d[1],i=d[2]?parseFloat(d[2]):null,o=d[3]?parseFloat(d[3]):null);const c=()=>{let e=a.selectionStart,r=a.value;n.test(r)||(r=r.replace(/[^0-9.]/g,"").replace(/(\..*?)\..*/,"$1").replace(/(\.\d{2}).*/,"$1")),!r||r.includes(".")||r.endsWith(".")||(r=parseFloat(r).toFixed(2)),a.value=r;const l=r.indexOf(".");-1!==l&&e>l&&(e=Math.min(e,r.length)),a.setSelectionRange(e,e);let i=a.nextElementSibling;i&&i.classList.contains("amount-display")||(i=t.createElement("div"),i.className="amount-display",i.style.color="green",a.parentNode.insertBefore(i,a.nextSibling)),i.textContent=`${s} ${r||"0.00"} .`},u=()=>{if(a.readOnly)return;let e=parseFloat(a.value||"0").toFixed(2),t=a.nextElementSibling;return null!==i&&e<i?(b(a,`Amount must be at least ${i.toFixed(2)} ${s}.`),a.style.border="2px solid red",a.value="",void(t&&(t.textContent=""))):null!==o&&e>o?(b(a,`Amount must not exceed ${o.toFixed(2)} ${s}.`),a.style.border="2px solid red",a.value="",void(t&&(t.textContent=""))):(a.style.border="",void(a.value=e))};"1"!==a.dataset.kilAmountBound&&(a.addEventListener("input",c),a.addEventListener("blur",u),a.dataset.kilAmountBound="1"),"keyup"!==e.type&&"change"!==e.type||c()}if("password"===a.type){l=!0;const{bars:r,label:s,rulesUl:i}=v(a),o=a.getAttribute("data-kilvish-password")||"12",[d,c]=o.split("_"),u=parseInt(d,10)||12,p=parseInt(c||"128",10);n=new RegExp(`^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[\\W_]).{${u},${p}}$`);const m={length:`Password must be between ${u} and ${p} characters long`,uppercase:"At least one uppercase letter (A-Z)",lowercase:"At least one lowercase letter (a-z)",number:"At least one number (0-9)",special:"At least one special character (!@#$%^&*)",sequential:"No sequential characters (e.g., 1234, abcd)"},y={};Object.keys(m).forEach((e=>{let a=i.querySelector(`li[data-rule="${e}"]`);a||(a=t.createElement("li"),a.setAttribute("data-rule",e),a.textContent=`❌ ${m[e]}`,a.style.color="red",a.style.fontSize="12px",i.appendChild(a)),y[e]=a}));const f=e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1},h=e=>{let t=0;return e.length>=u&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),f(e)&&(t-=2),Math.max(0,t)},g=a.value||"",b={length:g.length>=u&&g.length<=p,uppercase:/[A-Z]/.test(g),lowercase:/[a-z]/.test(g),number:/\d/.test(g),special:/[\W_]/.test(g),sequential:!f(g)};Object.keys(b).forEach((e=>{const t=b[e];y[e].textContent=`${t?"✅":"❌"} ${m[e]}`,y[e].style.color=t?"green":"red"}));const x=h(g);r.forEach((e=>e.style.background="lightgray")),x<=2?(r[0]&&(r[0].style.background="red"),s.textContent="Weak",s.style.color="red"):x<=4?(r[0]&&(r[0].style.background="yellow"),r[1]&&(r[1].style.background="yellow"),s.textContent="Medium",s.style.color="orange"):(r[0]&&(r[0].style.background="green"),r[1]&&(r[1].style.background="green"),r[2]&&(r[2].style.background="green"),s.textContent="Strong",s.style.color="green");const k=n.test(g)&&Object.values(b).every(Boolean);return a.style.border=k?"1px solid green":"1px solid red",void(k||"change"!==e.type||(a.value=""))}if("file"===a.type){l=!0;const e=a.getAttribute("data-kilvish-file")||"image",[t,...r]=e.split("_"),n=s[e]||s[t]||s.image,o=a.files;let d=1,c=1/0;if(r.length>=2&&(d=parseInt(r[0],10),c=parseInt(r[1],10)),o.length<d||o.length>c)return b(a,`Please select between ${d} and ${c} valid file(s).`),a.value="",a.style.border="1px solid red",!1;const u=i[e]||t.toUpperCase();for(const e of o)if(!n.includes(e.type))return b(a,`Invalid file type. Allowed types: ${u}.`),a.value="",a.style.border="1px solid red",!1}else l&&("keyup"===e.type&&(n.test(a.value)||("password"!==a.type&&b(a,"Invalid character entered!"),a.style.border="1px solid red")),"change"===e.type&&(n.test(a.value)?(a.style.border="",r(a)):(a.value="",b(a,"Invalid character or format!"),a.style.border="1px solid red")))}function g(){t.querySelectorAll("input[type='password']").forEach((e=>{if(e.hasAttribute("data-ignore-kilvish"))return;if("1"===e.dataset.kilPassStrengthBound)return;const{bars:t,label:a}=v(e),r=e.getAttribute("data-kilvish-password")||"12",[n]=r.split("_").map(Number);e.addEventListener("input",(e=>{const r=(e=>{let t=0;return e.length>=n&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),(e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1})(e)&&(t-=2),Math.max(0,t)})(e.target.value);t.forEach((e=>e.style.background="lightgray")),r<=2?(t[0].style.background="red",a.textContent="Weak",a.style.color="red"):r<=4?(t[0].style.background="yellow",t[1].style.background="yellow",a.textContent="Medium",a.style.color="orange"):(t[0].style.background="green",t[1].style.background="green",t[2].style.background="green",a.textContent="Strong",a.style.color="green")})),e.dataset.kilPassStrengthBound="1"}))}function b(e,a){const r=e.form?e.form:e.closest("form");if(!r)return;let n=null;if(e&&e.tagName&&/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName))n=e;else if(e&&e.querySelector){const t=e.querySelectorAll("input,select,textarea");n=t.length?t[t.length-1]:null}let s=e,i="beforeend",o="container";if(n){const e=n.nextElementSibling;"SELECT"===n.tagName&&e&&(e.classList.contains("select2")||e.classList.contains("select2-container"))?(s=e,i="afterend",o=n.name||n.id||"select"):n.parentElement&&n.parentElement.classList.contains("input-group")?(s=n.parentElement,i="afterend",o=n.name||n.id||"inputgroup"):(s=n,i="afterend",o=n.name||n.id||"field")}const d=`kil_err_${String(o).replace(/[^a-zA-Z0-9_\-]/g,"_")}`;let c=r.querySelector(`#${d}`);if(c||(c=t.createElement("div"),c.id=d,c.className="error-message is-hidden","beforeend"===i?s.insertAdjacentElement("beforeend",c):s.insertAdjacentElement("afterend",c)),c.textContent=a||"",c.classList.remove("is-hidden"),n)l(n);else{const t=e.querySelector("input[required],select[required],textarea[required]")||e.querySelector("input,select,textarea");t&&l(t)}}function v(e){const a=function(e){return e.parentElement&&e.parentElement.classList.contains("input-group")?e.parentElement:e}(e),r=e.name||e.id||"password",n=`kil_passui_${String(r).replace(/[^a-zA-Z0-9_-]/g,"_")}`;let l=a.parentNode.querySelector(`#${n}`);if(!l){l=t.createElement("div"),l.id=n,l.className="kil-passui";const e=t.createElement("div");e.className="password-strength";const r=t.createElement("div");r.className="bars";const s=t.createElement("div");s.className="bar";const i=t.createElement("div");i.className="bar";const o=t.createElement("div");o.className="bar",r.append(s,i,o);const d=t.createElement("span");d.className="label",d.textContent="Weak",d.style.fontSize="12px",e.append(r,d);const c=t.createElement("ul");c.className="password-validation",l.append(e,c),a.insertAdjacentElement("afterend",l)}const s=l.querySelectorAll(".bar"),i=l.querySelector(".password-strength .label"),o=l.querySelector(".password-validation");return{wrap:l,bars:s,label:i,rulesUl:o}}function x(e){if("1"===e.dataset.kileyeAttached)return;if(e.hasAttribute("data-kileye-false"))return;const{anchor:a}=function(e){const a=e.closest(".input-group");if(a)return a.classList.add("kil-eye-rel"),e.classList.add("kil-eye-pad"),{anchor:a};if(!e.parentElement.classList.contains("kil-eye-wrap")){const a=t.createElement("span");a.className="kil-eye-wrap",e.parentNode.insertBefore(a,e),a.appendChild(e)}return e.classList.add("kil-eye-pad"),{anchor:e.parentElement}}(e);a.style.overflow="visible";let r=a.querySelector(".kil-eye-btn");r||(r=t.createElement("button"),r.type="button",r.className="kil-eye-btn",r.setAttribute("tabindex","-1"),r.setAttribute("aria-label","Show/Hide password"),r.innerHTML='<i class="fa fa-eye-slash" aria-hidden="true"></i>',a.appendChild(r));const n=e.getAttribute("data-kileye-color");n&&(r.style.color=n);const l=()=>r.querySelector("i");function s(){e.type="text",l()&&(l().classList.remove("fa-eye-slash"),l().classList.add("fa-eye"))}function i(){e.type="password",l()&&(l().classList.remove("fa-eye"),l().classList.add("fa-eye-slash"))}function o(){"password"===e.type?s():i()}const d=(e.getAttribute("data-kileye-show")||"hold").toLowerCase(),c=(e.getAttribute("data-kileye-initial")||"auto").toLowerCase();"fix"===d||"on"===c?s():"off"!==c&&"auto"!==c||i(),r.onmousedown=r.onmouseup=r.onmouseleave=r.onclick=null,r.ontouchstart=r.ontouchend=r.ontouchcancel=null,"toggle"===d||"fix"===d?(r.onclick=e=>{e.preventDefault(),o()},r.addEventListener("touchstart",(e=>{e.preventDefault(),o()}),{passive:!1})):(r.onmousedown=e=>{e.preventDefault(),s()},r.onmouseup=()=>i(),r.onmouseleave=()=>i(),r.onblur=()=>i(),r.addEventListener("touchstart",(e=>{e.preventDefault(),s()}),{passive:!1}),r.addEventListener("touchend",(()=>i())),r.addEventListener("touchcancel",(()=>i()))),e.addEventListener("blur",(()=>{"hold"===d&&i()})),e.dataset.kileyeAttached="1"}return"loading"===t.readyState?t.addEventListener("DOMContentLoaded",f):f(),function(){if(t.getElementById("kil-pass-style"))return;const e=t.createElement("style");e.id="kil-pass-style",e.textContent="\n .kil-passui { display:block; width:100%; margin-top:6px; }\n .kil-passui .password-strength { display:flex; align-items:center; gap:10px; }\n .kil-passui .password-strength .bars { display:flex; gap:4px; }\n .kil-passui .password-strength .bar { height:5px; width:30px; border-radius:3px; background:lightgray; }\n .kil-passui .password-validation { list-style:none; padding:0; margin:6px 0 0; }\n .kil-passui .password-validation li { font-size:12px; margin:2px 0; }\n ",t.head.appendChild(e)}(),function(){if(t.getElementById("kil-eye-style"))return;const e=t.createElement("style");e.id="kil-eye-style",e.textContent="\n .kil-eye-rel { position: relative !important; overflow: visible !important; }\n .kil-eye-wrap{ position:relative; display:block; }\n .kil-eye-btn{\n position:absolute; top:50%; right:10px; transform:translateY(-50%);\n display:inline-flex; align-items:center; justify-content:center;\n background:transparent; border:0; padding:0; margin:0;\n height:auto; width:auto; line-height:1; cursor:pointer; outline:none;\n z-index: 10; /* <-- stays above focused input */\n pointer-events: auto;\n }\n .kil-eye-btn i{ font-size:16px; }\n .kil-eye-pad { padding-right: 38px !important; }\n .kil-eye-btn { flex: 0 0 auto; }\n ",t.head.appendChild(e)}(),{validateRequiredFields:i,addRealTimeValidation:o,validateForm:d,addAsteriskToRequiredFields:u,attachInputEvents:p,addValidateFormToSubmitButtons:m,validateKilvishInput:h,addErrorMessage:b,init:f,initPasswordStrengthMeter:g,normalizeRequiredStars:c}}));
|
|
2
|
+
!function(e,t){"object"==typeof module&&module.exports?module.exports=t(e):"function"==typeof define&&define.amd?define((function(){return t(e)})):e&&(e.kilvalidate=t(e))}("undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:void 0,(function(e){if(!e||!e.document){const e=()=>{},t=()=>!1;return{validateRequiredFields:t,addRealTimeValidation:e,validateForm:t,addAsteriskToRequiredFields:e,attachInputEvents:e,addValidateFormToSubmitButtons:e,validateKilvishInput:e,addErrorMessage:e,init:e,initPasswordStrengthMeter:e}}const t=e.document;!function(){if(t.getElementById("kil-error-style"))return;const e=t.createElement("style");e.id="kil-error-style",e.textContent="\n .error-message {\n display:block;\n min-height:16px; /* reserves space even when empty */\n margin-top:4px;\n font-size:12px;\n color:#d32f2f;\n line-height:1.25;\n opacity:1;\n transition: opacity .12s ease;\n }\n .error-message.is-hidden{ opacity:0; }\n ",t.head.appendChild(e)}();const a=t=>e.CSS&&"function"==typeof e.CSS.escape?e.CSS.escape(String(t)):String(t).replace(/["\\]/g,"\\$&");function r(e){if(!e)return null;if(e.tagName&&"FORM"===String(e.tagName).toUpperCase())return e;if("string"==typeof e){return/^[#.\[]/.test(e)||e.includes(" ")||e.includes("[")?t.querySelector(e):t.getElementById(e)||t.querySelector(e)}return e.querySelector?e:null}function n(e){if(!e)return null;const r=e.form||t;let n=null;if(e.id&&(n=r.querySelector(`label[for="${a(e.id)}"]`)),!n&&e.name&&(n=r.querySelector(`label[for="${a(e.name)}"]`)),n||(n=e.closest("label")),!n){const t=e.closest("fieldset");t&&(n=t.querySelector("legend"))}return n}function s(e){const a=n(e);if(!a)return;let r=a.querySelector(".kil-required-star");r||(r=t.createElement("span"),r.className="kil-required-star",r.textContent=" *",a.appendChild(r)),r.style.visibility="visible"}function l(e){const t=n(e);if(!t)return;const a=t.querySelector(".kil-required-star");a&&(a.style.visibility="hidden")}function i(e){const t=r(e);if(!t)return console.warn("Form not found for validation:",e),!1;const a=t.querySelectorAll("input[required], select[required], textarea[required]"),n=(t.querySelectorAll("fieldset.radios"),t.querySelectorAll('input[type="radio"]')),s={},l=new Set;t.querySelectorAll('input[type="checkbox"]').forEach((e=>{const t=e.name;s[t]||(s[t]=[]),s[t].push(e),e.hasAttribute("required")&&l.add(t)}));t.querySelectorAll(".select2");let i=!0,o="This Field is Required.";if(t.querySelectorAll(".error-message").forEach((e=>{e.textContent="",e.classList.add("is-hidden")})),a.forEach((e=>{e.style.border=""})),a.forEach((e=>{const t=e.closest(".form-group")||e.parentNode;e.parentNode;if("date"==e.type){o="Please Select Date",e.style.border="";e.value.trim()||(i=!1,e.style.border="1px solid red",b(t,o))}else o="comments"==e.name?"Please Enter Comments":"email"==e.type?"Please Enter Email":"password"==e.type?"Please Enter Password":"This Field is Required.";const a=e.getAttribute("data-kilvish-name");let r;if(o=`${a||"This"} Field is Required.`,("tel"===e.type||e.hasAttribute("data-kilvish-tel"))&&(r=function(e){const t=e.closest(".kiltel-phone-wrap")||e.parentElement,a=t&&(t.querySelector('input[name="contact"]')||t.querySelector("#contact"));if(a)return(a.value||"").replace(/\D/g,"").length<7;const r=(e.value||"").trim().replace(/\s|-/g,"");return!r||(!!/^\+?$/.test(r)||(!!/^\+?\d{1,4}$/.test(r)||r.replace(/\D/g,"").length<7))}(e),r&&(o=`${a||"Phone"} is required (enter full number, not just country code).`)),r)return i=!1,e.style.border="1px solid red",void b(e,o);e.value.trim()||(i=!1,e.style.border="1px solid red",b(t,o))})),n.length>0){const e={};n.forEach((t=>{const a=t.name;e[a]||(e[a]={isSelected:!1,groupElement:t.closest(".form-group")||t.closest(".mb-3")||t.closest(".form-check")||t.closest(".radios")||t.closest(".col-md-6")}),t.checked&&(e[a].isSelected=!0)})),Object.entries(e).forEach((([e,t])=>{if(!t.isSelected){i=!1;const a="Please select one option.";if(!t.groupElement)return void console.error("Invalid group element for radio group:",e);b(t.groupElement,a)}}))}return Object.keys(s).forEach((e=>{const t=s[e];if(t.some((e=>e.hasAttribute("data-ignore-kilvish"))))return;if(!t.some((e=>e.checked))){i=!1;const a=l.has(e)?"Please check this box to proceed":"Please select at least one option.";b(t[0].closest(".form-group")||t[0].closest(".form-check")||t[0].closest(".checkbox-container")||t[0].closest(".some-other-container"),a)}})),i}function o(e){const t=r(e);if(!t)return;const a=t.querySelectorAll("input[required], select[required], textarea[required]"),n=(e,t=!0)=>{t?s(e):l(e)};function i(e){const t=e.form||e.closest("form");if(!t)return;const a=e.nextElementSibling;let r=e,n="afterend",s=e.name||e.id||"field";"SELECT"===e.tagName&&a&&(a.classList.contains("select2")||a.classList.contains("select2-container"))?(r=a,n="afterend",s=e.name||e.id||"select"):e.parentElement&&e.parentElement.classList.contains("input-group")&&(r=e.parentElement,n="afterend",s=e.name||e.id||"inputgroup");const i=t.querySelector(`#kil_err_${String(s).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);i&&(i.textContent="",i.classList.add("is-hidden")),e.style.border="",l(e)}a.forEach((e=>{if("1"===e.dataset.kilRealtimeBound)return;const t=()=>{e.value.trim()?(i(e),n(e,!1)):n(e,!0)};e.addEventListener("input",t),e.addEventListener("change",t),e.dataset.kilRealtimeBound="1"}));const o=t.querySelectorAll('input[type="radio"]');[...new Set(Array.from(o).map((e=>e.name)))].forEach((e=>{const a=t.querySelectorAll(`input[type="radio"][name="${e}"]`);a.forEach((e=>{"1"!==e.dataset.kilRadioBound&&(e.addEventListener("change",(()=>{Array.from(a).some((e=>e.checked))&&i(e)})),e.dataset.kilRadioBound="1")}))}));const d=t.querySelectorAll('input[type="checkbox"]');[...new Set(Array.from(d).map((e=>e.name)))].forEach((e=>{const a=t.querySelectorAll(`input[type="checkbox"][name="${e}"]`);a.forEach((e=>{"1"!==e.dataset.kilCheckboxBound&&(e.addEventListener("change",(()=>{Array.from(a).some((e=>e.checked))&&i(e)})),e.dataset.kilCheckboxBound="1")}))}))}function d(t,a){const r=i(t);if(!r){const t=a||e.event;t&&t.preventDefault&&t.preventDefault()}return r}function c(e=t){e.querySelectorAll("label, legend").forEach((e=>{e.querySelectorAll("span").forEach((e=>{e.classList.contains("kil-required-star")||"*"!==e.textContent.trim()||e.remove()}));const t=e.querySelectorAll(".kil-required-star");for(let e=1;e<t.length;e++)t[e].remove()}))}function u(){t.querySelectorAll("input[required], select[required], textarea[required]").forEach(s)}function p(){t.querySelectorAll("input, select, textarea").forEach((e=>{"1"!==e.dataset.kilInputBound&&(e.hasAttribute("data-ignore-kilvish")||(e.addEventListener("keyup",f),e.addEventListener("change",f),e.dataset.kilInputBound="1"))}))}function m(){t.querySelectorAll("form").forEach((e=>{const t=e.id;"1"!==e.dataset.kilFormSubmitBound&&(e.addEventListener("submit",(t=>d(e,t))),e.dataset.kilFormSubmitBound="1");const a=t?`#${t}`:e;e.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((e=>{"1"!==e.dataset.kilSubmitBound&&(e.addEventListener("click",(e=>d(a,e))),e.dataset.kilSubmitBound="1")}))}))}!function(){if(t.getElementById("kil-req-style"))return;const e=t.createElement("style");e.id="kil-req-style",e.textContent="\n .kil-required-star{ color:#d32f2f; margin-left:2px; }\n .error-message{ display:block; min-height:16px; margin-top:4px; font-size:12px; color:#d32f2f; line-height:1.25; opacity:1; transition:opacity .12s ease; }\n .error-message.is-hidden{ opacity:0; }\n ",t.head.appendChild(e)}();let h=null;function y(){c(),u();t.querySelectorAll("form").forEach((e=>{const t=e.id;o(t||e)})),p(),m(),g(),t.querySelectorAll('input[type="password"]').forEach(x),!h&&e.MutationObserver&&(h=new MutationObserver((e=>{for(const t of e)t.addedNodes&&t.addedNodes.forEach((e=>{e instanceof HTMLElement&&(e.matches&&e.matches('input[type="password"]')&&x(e),e.querySelectorAll&&e.querySelectorAll('input[type="password"]').forEach(x))}))})),h.observe(t.documentElement,{childList:!0,subtree:!0}))}function f(e){const a=e.target;if(a.hasAttribute("data-ignore-kilvish"))return;function r(e){const t=e.form||e.closest("form");if(!t)return;const a=e.nextElementSibling;let r=e.name||e.id||"field";"SELECT"===e.tagName&&a&&(a.classList.contains("select2")||a.classList.contains("select2-container"))?r=e.name||e.id||"select":e.parentElement&&e.parentElement.classList.contains("input-group")&&(r=e.name||e.id||"inputgroup");const n=t.querySelector(`#kil_err_${String(r).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);n&&(n.textContent="",n.classList.add("is-hidden")),e.style.border=""}let n=/^[a-zA-Z\s]*$/;const s=a.hasAttribute("data-kilvish-num")||a.hasAttribute("data-kilvish-num11")||a.hasAttribute("data-kilvish-char")||a.hasAttribute("data-kilvish-amount")||a.hasAttribute("data-kilvish-date")||a.hasAttribute("data-kilvish-dategroup")||a.hasAttribute("data-kilvish-age")||a.hasAttribute("data-kilvish-file")||a.hasAttribute("data-kilvish-password"),l=a.hasAttribute("data-kilvish-default")||a.form&&a.form.hasAttribute("data-kilvish-default");let i=l;const o={image:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],doc:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pdf:["application/pdf"],mix:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],only_pdf_image:["application/pdf","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],only_doc_image:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"]},d={image:"Image",doc:"Document",pdf:"PDF",mix:"Image & Document",only_pdf_image:"PDF & Image",only_doc_image:"Document & Image"};if(r(a),s||l){if("description"===a.name||"address"===a.name){if(i=!0,n=/^[a-zA-Z0-9@,._\s-'"*]*$/,a.value.length>400)return b(a,"Input exceeds the maximum length of 400 characters!"),a.style.border="1px solid red",void(a.value=a.value.substring(0,400))}else if("firstname"===a.name||"lastname"===a.name||"appointment_by"===a.name){i=!0,n=/^[a-zA-Z\s-]*$/;const t=/^[a-zA-Z0-9._@-\s]+$/,r=a.value;if(t.test(r)&&(r.length>20||r.length<2))return b(a,"This Field Must Be Between 2 And 20 Characters."),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("otp"===a.name){i=!0,n=/^\d{6}$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&6!==r.length)return b(a,"OTP must be exactly 6 digits"),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("number_of_items"===a.name){i=!0,n=/^\d{0,6}(\.\d{0,2})?$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&r.length>3)return b(a,"Pacakge Number Cannot Be Exceed 3 Digits"),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("contact"===a.name||"agent_contact"===a.id||"fullcontact"===a.name)i=!0,n=/^[\d\-\s]{0,20}$/;else if("number"===a.type){i=!0,n=/^\d{0,20}$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&(r.length>20||r.length<1))return b(a,"This Must Be Between 1 And 20 Digits."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("tel"===a.type){i=!0;let t=a.value.trim().replace(/\s+/g,"");a.value=t;if(n=/^\+?\d{7,15}$/,!/^\+?\d{7,15}$/.test(t))return b(a,"Enter a valid phone number (7–15 digits, optional +)."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("kildate"===a.name){i=!0,n=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const t=a.value.trim(),r=new Date(t.replace(/[-\/]/g,"/")),s=new Date;s.setHours(0,0,0,0);const l=a.getAttribute("data-kilvish-date");if(l){const[t,n]=l.replace("_","").split("_").map(Number),i=new Date(s),o=new Date(s);if(i.setFullYear(s.getFullYear()-t),o.setFullYear(s.getFullYear()-n),r>i||r<o)return b(a,`Birthday cannot be less than ${t} years ago or more than ${n} years in the future.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(r<s)return b(a,"The date cannot be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else{if("date"===a.type||"month"===a.type){i=!0,n=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=a.value.trim(),s="month"===a.type?new Date(r+"-01"):new Date(r.replace(/[-\/]/g,"/")),l=new Date;l.setHours(0,0,0,0);const o=a.getAttribute("data-kilvish-date");if(o)if(/^_(\d+)_(\d+)$/.test(o)){const[t,r]=o.replace("_","").split("_").map(Number),n=new Date(l),i=new Date(l);if(n.setFullYear(l.getFullYear()-t),i.setFullYear(l.getFullYear()-r),s>n||s<i)return b(a,`Age must be between ${t} and ${r} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^_(\d+)$/.test(o)){const t=Number(o.replace("_","")),r=new Date(l);if(r.setFullYear(l.getFullYear()-t),s.getTime()!==r.getTime())return b(a,`You must be exactly ${t} years old.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/future/.test(o)){if("future"===o&&s<=l)return b(a,"The selected date must be in the future."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("today_future"===o&&s<l)return b(a,"The selected date cannot be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/(\d+)_days_future/.test(o)){const t=Number(o.match(/(\d+)_days_future/)[1]),r=new Date(l);if(r.setDate(l.getDate()+t),s>r||s<l)return b(a,`The selected date must be within the next ${t} days.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_future$/.test(o)){const t=Number(o.match(/^(\d+)_years_future$/)[1]),r=new Date(l);if(r.setFullYear(l.getFullYear()+t),s<l||s>r)return b(a,`The date must be within the next ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_after$/.test(o)){const t=Number(o.match(/^(\d+)_years_after$/)[1]),r=new Date(l);if(r.setFullYear(l.getFullYear()+t),s.getTime()!==r.getTime())return b(a,`The date must be exactly ${t} years after today.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}else if(/past/.test(o)){if("past"===o&&s>=l)return b(a,"The selected date must be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/^(\d+)_years_past$/.test(o)){const t=Number(o.match(/^(\d+)_years_past$/)[1]),r=new Date(l);if(r.setFullYear(l.getFullYear()-t),s>l||s<r)return b(a,`The date must be within the past ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}else if(/^(\d+)_years_before$/.test(o)){const t=Number(o.match(/^(\d+)_years_before$/)[1]),r=new Date(l);if(r.setFullYear(l.getFullYear()-t),s>=r)return b(a,`The date must be before ${t} years ago.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_after$/.test(o)){const t=Number(o.match(/^(\d+)_years_after$/)[1]),r=new Date(l);if(r.setFullYear(l.getFullYear()+t),s<=r)return b(a,`The date must be after ${t} years from today.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/Between_(\d+)_(\d+)/.test(o)){const[t,r]=o.match(/Between_(\d+)_(\d+)/).slice(1,3).map(Number),n=new Date(t,0,1),l=new Date(r,11,31);if(s<n||s>l)return b(a,`The date must be between ${t} and ${r}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/from_(\d+)/.test(o)){const t=Number(o.match(/from_(\d+)/)[1]);if(s<new Date(t,0,1))return b(a,`The date must be from the year ${t} onwards.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/till_(\d+)/.test(o)){const t=Number(o.match(/till_(\d+)/)[1]);if(s>new Date(t,11,31))return b(a,`The date must be till the year ${t}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else{if("not_today"===o&&s.getTime()===l.getTime())return b(a,"Today's date is not allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("weekday"===o&&(0===s.getDay()||6===s.getDay()))return b(a,"Only weekdays (Monday to Friday) are allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("weekend"===o&&s.getDay()>=1&&s.getDay()<=5)return b(a,"Only weekends (Saturday and Sunday) are allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("first_of_month"===o&&1!==s.getDate())return b(a,"The date must be the first day of the month."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/^exact_(\d+)$/.test(o)){const t=Number(o.match(/^exact_(\d+)$/)[1]),r=new Date(l);if(r.setFullYear(l.getFullYear()-t),s.getTime()!==r.getTime())return b(a,`You must be exactly ${t} years old.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if("last_of_month"===o){const t=new Date(s.getFullYear(),s.getMonth()+1,0).getDate();if(s.getDate()!==t)return b(a,"The date must be the last day of the month."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}const d=a.getAttribute("data-kilvish-dategroup");if(d&&/.+_[12]$/.test(d)){const[r,n]=d.split("_"),s="1"===n?"2":"1",l=t.querySelector(`[data-kilvish-dategroup="${r}_${s}"]`);if(l&&l.value){const t="month"===a.type?new Date(a.value+"-01"):new Date(a.value.replace(/[-\/]/g,"/")),i="month"===l.type?new Date(l.value+"-01"):new Date(l.value.replace(/[-\/]/g,"/"));if(!("1"===n&&t<=i||"2"===n&&t>=i)){const t=a.dataset.kilvishDate_name||`Field (${r}_${n})`,i=l.dataset.kilvishDate_name||`Field (${r}_${s})`;return b(a,`${t} must be ${"1"===n?"before or same as":"after or same as"} ${i}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}}return void(a.style.border="")}if("age"===a.name){i=!0;const t=a.value.trim(),r=parseInt(t,10);if(isNaN(r))return b(a,"Please enter a valid number for age."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));const n=a.getAttribute("data-kilvish-age")||"18";if(/^(\d+)$/.test(n)){const t=Number(n);if(r!==t)return b(a,`Age must be exactly ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_(\d+)$/.test(n)){const[t,s]=n.split("_").map(Number);if(r<t)return b(a,`Minimum age must be ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(r>s)return b(a,`Age cannot exceed ${s} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}return void(a.style.border="")}}if("model_name"===a.name||"models[]"===a.name)i=!0,n=/^[a-zA-Z0-9]{4,20}$/;else if("email"===a.type){i=!0,n=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;const t=/^[a-zA-Z0-9._@-]+$/,r=a.value;if(t.test(r)&&!n.test(r))return b(a,"Invalid Email Format."),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}if(a.hasAttribute("data-kilvish-num")){i=!0;const t=a.value,r=a.getAttribute("data-kilvish-num");n=/^[0-9]*$/;let s=null,l=null;const o=r.match(/^_(\d+)_(\d+)$/);o&&(s=parseInt(o[1],10),l=parseInt(o[2],10));const d=r.match(/^exact_(\d+)$/),c=d?parseInt(d[1],10):null;/^\d*$/.test(t)?null!==c&&t.length!==c?(b(a,`This field must contain exactly ${c} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):s&&t.length<s||l&&t.length>l?(b(a,`This Field Must be between ${s} and ${l} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):a.style.border="":(b(a,"Only numerical characters are allowed."),a.style.border="2px solid red")}if(a.hasAttribute("data-kilvish-num11")){i=!0;const t=a.value,r=a.getAttribute("data-kilvish-num");n=/^[0-9]*$/;let s=null,l=null;const o=r?r.match(/^_(\d+)_(\d+)$/):null;o&&(s=parseInt(o[1],10),l=parseInt(o[2],10)),"exact_20"===r&&(n=/^[0-9]{20}$/),n.test(t)?s&&t.length<s||l&&t.length>l?(b(a,`This Field Must be between ${s} and ${l} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):a.style.border="":(b(a,"exact_20"===r?"This field must contain exactly 20 digits.":"Only numerical characters are allowed."),a.style.border="2px solid red")}if(a.hasAttribute("data-kilvish-char")){i=!0;const t=a.value,r=a.getAttribute("data-kilvish-char");if(r.startsWith("Yes")||r.startsWith("mix")){"mix"===r?n=/^[a-zA-Z0-9]*$/:"Yes"===r&&(n=/^[a-zA-Z]*$/);const s=r.split("_").slice(1).join("");if(s&&(n=new RegExp(`^[a-zA-Z0-9${s}]*$`)),!n.test(t))return b(a,"Invalid character entered!"),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}if(a.hasAttribute("data-kilvish-amount")){i=!0;const r=a.getAttribute("data-kilvish-amount");n=/^\d+(\.\d{0,2})?$/;let s="USD",l=null,o=null;const d=r.match(/^([A-Z]{3})(?:_(\d+)_(\d+))?$/);d&&(s=d[1],l=d[2]?parseFloat(d[2]):null,o=d[3]?parseFloat(d[3]):null);const c=()=>{let e=a.selectionStart,r=a.value;n.test(r)||(r=r.replace(/[^0-9.]/g,"").replace(/(\..*?)\..*/,"$1").replace(/(\.\d{2}).*/,"$1")),!r||r.includes(".")||r.endsWith(".")||(r=parseFloat(r).toFixed(2)),a.value=r;const l=r.indexOf(".");-1!==l&&e>l&&(e=Math.min(e,r.length)),a.setSelectionRange(e,e);let i=a.nextElementSibling;i&&i.classList.contains("amount-display")||(i=t.createElement("div"),i.className="amount-display",i.style.color="green",a.parentNode.insertBefore(i,a.nextSibling)),i.textContent=`${s} ${r||"0.00"} .`},u=()=>{if(a.readOnly)return;let e=parseFloat(a.value||"0").toFixed(2),t=a.nextElementSibling;return null!==l&&e<l?(b(a,`Amount must be at least ${l.toFixed(2)} ${s}.`),a.style.border="2px solid red",a.value="",void(t&&(t.textContent=""))):null!==o&&e>o?(b(a,`Amount must not exceed ${o.toFixed(2)} ${s}.`),a.style.border="2px solid red",a.value="",void(t&&(t.textContent=""))):(a.style.border="",void(a.value=e))};"1"!==a.dataset.kilAmountBound&&(a.addEventListener("input",c),a.addEventListener("blur",u),a.dataset.kilAmountBound="1"),"keyup"!==e.type&&"change"!==e.type||c()}if("password"===a.type){i=!0;const{bars:r,label:s,rulesUl:l}=v(a),o=a.getAttribute("data-kilvish-password")||"12",[d,c]=o.split("_"),u=parseInt(d,10)||12,p=parseInt(c||"128",10);n=new RegExp(`^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[\\W_]).{${u},${p}}$`);const m={length:`Password must be between ${u} and ${p} characters long`,uppercase:"At least one uppercase letter (A-Z)",lowercase:"At least one lowercase letter (a-z)",number:"At least one number (0-9)",special:"At least one special character (!@#$%^&*)",sequential:"No sequential characters (e.g., 1234, abcd)"},h={};Object.keys(m).forEach((e=>{let a=l.querySelector(`li[data-rule="${e}"]`);a||(a=t.createElement("li"),a.setAttribute("data-rule",e),a.textContent=`❌ ${m[e]}`,a.style.color="red",a.style.fontSize="12px",l.appendChild(a)),h[e]=a}));const y=e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1},f=e=>{let t=0;return e.length>=u&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),y(e)&&(t-=2),Math.max(0,t)},g=a.value||"",b={length:g.length>=u&&g.length<=p,uppercase:/[A-Z]/.test(g),lowercase:/[a-z]/.test(g),number:/\d/.test(g),special:/[\W_]/.test(g),sequential:!y(g)};Object.keys(b).forEach((e=>{const t=b[e];h[e].textContent=`${t?"✅":"❌"} ${m[e]}`,h[e].style.color=t?"green":"red"}));const x=f(g);r.forEach((e=>e.style.background="lightgray")),x<=2?(r[0]&&(r[0].style.background="red"),s.textContent="Weak",s.style.color="red"):x<=4?(r[0]&&(r[0].style.background="yellow"),r[1]&&(r[1].style.background="yellow"),s.textContent="Medium",s.style.color="orange"):(r[0]&&(r[0].style.background="green"),r[1]&&(r[1].style.background="green"),r[2]&&(r[2].style.background="green"),s.textContent="Strong",s.style.color="green");const k=n.test(g)&&Object.values(b).every(Boolean);return a.style.border=k?"1px solid green":"1px solid red",void(k||"change"!==e.type||(a.value=""))}if("file"===a.type){i=!0;const e=a.getAttribute("data-kilvish-file")||"image",[t,...r]=e.split("_"),n=o[e]||o[t]||o.image,s=a.files;let l=1,c=1/0;if(r.length>=2&&(l=parseInt(r[0],10),c=parseInt(r[1],10)),s.length<l||s.length>c)return b(a,`Please select between ${l} and ${c} valid file(s).`),a.value="",a.style.border="1px solid red",!1;const u=d[e]||t.toUpperCase();for(const e of s)if(!n.includes(e.type))return b(a,`Invalid file type. Allowed types: ${u}.`),a.value="",a.style.border="1px solid red",!1}else i&&("keyup"===e.type&&(n.test(a.value)||("password"!==a.type&&b(a,"Invalid character entered!"),a.style.border="1px solid red")),"change"===e.type&&(n.test(a.value)?(a.style.border="",r(a)):(a.value="",b(a,"Invalid character or format!"),a.style.border="1px solid red")))}}function g(){t.querySelectorAll("input[type='password']").forEach((e=>{if(e.hasAttribute("data-ignore-kilvish"))return;if("1"===e.dataset.kilPassStrengthBound)return;const{bars:t,label:a}=v(e),r=e.getAttribute("data-kilvish-password")||"12",[n]=r.split("_").map(Number);e.addEventListener("input",(e=>{const r=(e=>{let t=0;return e.length>=n&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),(e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1})(e)&&(t-=2),Math.max(0,t)})(e.target.value);t.forEach((e=>e.style.background="lightgray")),r<=2?(t[0].style.background="red",a.textContent="Weak",a.style.color="red"):r<=4?(t[0].style.background="yellow",t[1].style.background="yellow",a.textContent="Medium",a.style.color="orange"):(t[0].style.background="green",t[1].style.background="green",t[2].style.background="green",a.textContent="Strong",a.style.color="green")})),e.dataset.kilPassStrengthBound="1"}))}function b(e,a){const r=e.form?e.form:e.closest("form");if(!r)return;let n=null;if(e&&e.tagName&&/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName))n=e;else if(e&&e.querySelector){const t=e.querySelectorAll("input,select,textarea");n=t.length?t[t.length-1]:null}let l=e,i="beforeend",o="container";if(n){const e=n.nextElementSibling;"SELECT"===n.tagName&&e&&(e.classList.contains("select2")||e.classList.contains("select2-container"))?(l=e,i="afterend",o=n.name||n.id||"select"):n.parentElement&&n.parentElement.classList.contains("input-group")?(l=n.parentElement,i="afterend",o=n.name||n.id||"inputgroup"):(l=n,i="afterend",o=n.name||n.id||"field")}const d=`kil_err_${String(o).replace(/[^a-zA-Z0-9_\-]/g,"_")}`;let c=r.querySelector(`#${d}`);if(c||(c=t.createElement("div"),c.id=d,c.className="error-message is-hidden","beforeend"===i?l.insertAdjacentElement("beforeend",c):l.insertAdjacentElement("afterend",c)),c.textContent=a||"",c.classList.remove("is-hidden"),n)s(n);else{const t=e.querySelector("input[required],select[required],textarea[required]")||e.querySelector("input,select,textarea");t&&s(t)}}function v(e){const a=function(e){return e.parentElement&&e.parentElement.classList.contains("input-group")?e.parentElement:e}(e),r=e.name||e.id||"password",n=`kil_passui_${String(r).replace(/[^a-zA-Z0-9_-]/g,"_")}`;let s=a.parentNode.querySelector(`#${n}`);if(!s){s=t.createElement("div"),s.id=n,s.className="kil-passui";const e=t.createElement("div");e.className="password-strength";const r=t.createElement("div");r.className="bars";const l=t.createElement("div");l.className="bar";const i=t.createElement("div");i.className="bar";const o=t.createElement("div");o.className="bar",r.append(l,i,o);const d=t.createElement("span");d.className="label",d.textContent="Weak",d.style.fontSize="12px",e.append(r,d);const c=t.createElement("ul");c.className="password-validation",s.append(e,c),a.insertAdjacentElement("afterend",s)}const l=s.querySelectorAll(".bar"),i=s.querySelector(".password-strength .label"),o=s.querySelector(".password-validation");return{wrap:s,bars:l,label:i,rulesUl:o}}function x(e){if("1"===e.dataset.kileyeAttached)return;if(e.hasAttribute("data-kileye-false"))return;const{anchor:a}=function(e){const a=e.closest(".input-group");if(a)return a.classList.add("kil-eye-rel"),e.classList.add("kil-eye-pad"),{anchor:a};if(!e.parentElement.classList.contains("kil-eye-wrap")){const a=t.createElement("span");a.className="kil-eye-wrap",e.parentNode.insertBefore(a,e),a.appendChild(e)}return e.classList.add("kil-eye-pad"),{anchor:e.parentElement}}(e);a.style.overflow="visible";let r=a.querySelector(".kil-eye-btn");r||(r=t.createElement("button"),r.type="button",r.className="kil-eye-btn",r.setAttribute("tabindex","-1"),r.setAttribute("aria-label","Show/Hide password"),r.innerHTML='<i class="fa fa-eye-slash" aria-hidden="true"></i>',a.appendChild(r));const n=e.getAttribute("data-kileye-color");n&&(r.style.color=n);const s=()=>r.querySelector("i");function l(){e.type="text",s()&&(s().classList.remove("fa-eye-slash"),s().classList.add("fa-eye"))}function i(){e.type="password",s()&&(s().classList.remove("fa-eye"),s().classList.add("fa-eye-slash"))}function o(){"password"===e.type?l():i()}const d=(e.getAttribute("data-kileye-show")||"hold").toLowerCase(),c=(e.getAttribute("data-kileye-initial")||"auto").toLowerCase();"fix"===d||"on"===c?l():"off"!==c&&"auto"!==c||i(),r.onmousedown=r.onmouseup=r.onmouseleave=r.onclick=null,r.ontouchstart=r.ontouchend=r.ontouchcancel=null,"toggle"===d||"fix"===d?(r.onclick=e=>{e.preventDefault(),o()},r.addEventListener("touchstart",(e=>{e.preventDefault(),o()}),{passive:!1})):(r.onmousedown=e=>{e.preventDefault(),l()},r.onmouseup=()=>i(),r.onmouseleave=()=>i(),r.onblur=()=>i(),r.addEventListener("touchstart",(e=>{e.preventDefault(),l()}),{passive:!1}),r.addEventListener("touchend",(()=>i())),r.addEventListener("touchcancel",(()=>i()))),e.addEventListener("blur",(()=>{"hold"===d&&i()})),e.dataset.kileyeAttached="1"}return"loading"===t.readyState?t.addEventListener("DOMContentLoaded",y):y(),function(){if(t.getElementById("kil-pass-style"))return;const e=t.createElement("style");e.id="kil-pass-style",e.textContent="\n .kil-passui { display:block; width:100%; margin-top:6px; }\n .kil-passui .password-strength { display:flex; align-items:center; gap:10px; }\n .kil-passui .password-strength .bars { display:flex; gap:4px; }\n .kil-passui .password-strength .bar { height:5px; width:30px; border-radius:3px; background:lightgray; }\n .kil-passui .password-validation { list-style:none; padding:0; margin:6px 0 0; }\n .kil-passui .password-validation li { font-size:12px; margin:2px 0; }\n ",t.head.appendChild(e)}(),function(){if(t.getElementById("kil-eye-style"))return;const e=t.createElement("style");e.id="kil-eye-style",e.textContent="\n .kil-eye-rel { position: relative !important; overflow: visible !important; }\n .kil-eye-wrap{ position:relative; display:block; }\n .kil-eye-btn{\n position:absolute; top:50%; right:10px; transform:translateY(-50%);\n display:inline-flex; align-items:center; justify-content:center;\n background:transparent; border:0; padding:0; margin:0;\n height:auto; width:auto; line-height:1; cursor:pointer; outline:none;\n z-index: 10; /* <-- stays above focused input */\n pointer-events: auto;\n }\n .kil-eye-btn i{ font-size:16px; }\n .kil-eye-pad { padding-right: 38px !important; }\n .kil-eye-btn { flex: 0 0 auto; }\n ",t.head.appendChild(e)}(),{validateRequiredFields:i,addRealTimeValidation:o,validateForm:d,addAsteriskToRequiredFields:u,attachInputEvents:p,addValidateFormToSubmitButtons:m,validateKilvishInput:f,addErrorMessage:b,init:y,initPasswordStrengthMeter:g,normalizeRequiredStars:c}}));
|
package/kilvish.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){if(document.getElementById("kil-error-style"))return;const e=document.createElement("style");e.id="kil-error-style",e.textContent="\n .error-message {\n display:block;\n min-height:16px; /* reserves space even when empty */\n margin-top:4px;\n font-size:12px;\n color:#d32f2f;\n line-height:1.25;\n opacity:1;\n transition: opacity .12s ease;\n }\n .error-message.is-hidden{ opacity:0; }\n ",document.head.appendChild(e)}();const _escKey=e=>String(e||"").replace(/[^a-zA-Z0-9_\-]/g,"_");function getErrorAnchor(e){let t=null;if(e&&e.tagName&&/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName))t=e;else if(e&&e.querySelector){const r=e.querySelectorAll("input,select,textarea");t=r.length?r[r.length-1]:null}if(!t)return{anchor:e,mode:"beforeend",key:"container"};const r=t.nextElementSibling;return"SELECT"===t.tagName&&r&&(r.classList.contains("select2")||r.classList.contains("select2-container"))?{anchor:r,mode:"afterend",key:t.name||t.id||"select"}:t.parentElement&&t.parentElement.classList.contains("input-group")?{anchor:t.parentElement,mode:"afterend",key:t.name||t.id||"inputgroup"}:{anchor:t,mode:"afterend",key:t.name||t.id||"field"}}function getOrCreateErrorNode(e,t,r,a){const n=`kil_err_${_escKey(a)}`;let s=e.querySelector(`#${n}`);return s||(s=document.createElement("div"),s.id=n,s.className="error-message is-hidden","beforeend"===r?t.insertAdjacentElement("beforeend",s):t.insertAdjacentElement("afterend",s)),s}function findLabelFor(e){if(!e)return null;const t=e.form||document;let r=null;if(e.id&&(r=t.querySelector(`label[for="${CSS.escape(e.id)}"]`)),!r&&e.name&&(r=t.querySelector(`label[for="${CSS.escape(e.name)}"]`)),r||(r=e.closest("label")),!r){const t=e.closest("fieldset");t&&(r=t.querySelector("legend"))}return r}function ensureStarVisibleFor(e){const t=findLabelFor(e);if(!t)return;let r=t.querySelector(".kil-required-star");r||(r=document.createElement("span"),r.className="kil-required-star",r.textContent=" *",t.appendChild(r)),r.style.visibility="visible"}function hideStarFor(e){const t=findLabelFor(e);if(!t)return;const r=t.querySelector(".kil-required-star");r&&(r.style.visibility="hidden")}function isKiltelEmpty(e){const t=e.closest(".kiltel-phone-wrap")||e.parentElement,r=t&&(t.querySelector('input[name="contact"]')||t.querySelector("#contact"));if(r){return(r.value||"").replace(/\D/g,"").length<7}const a=(e.value||"").trim().replace(/\s|-/g,"");if(!a)return!0;if(/^\+?$/.test(a))return!0;if(/^\+?\d{1,4}$/.test(a))return!0;return a.replace(/\D/g,"").length<7}function validateRequiredFields(e){const t=document.querySelector(`${e}`),r=t.querySelectorAll("input[required], select[required], textarea[required]"),a=(t.querySelectorAll("fieldset.radios"),t.querySelectorAll('input[type="radio"]')),n={},s=new Set;t.querySelectorAll('input[type="checkbox"]').forEach((e=>{const t=e.name;n[t]||(n[t]=[]),n[t].push(e),e.hasAttribute("required")&&s.add(t)}));t.querySelectorAll(".select2");let o=!0,l="This Field is Required.";if(t.querySelectorAll(".error-message").forEach((e=>{e.textContent="",e.classList.add("is-hidden")})),r.forEach((e=>{e.style.border=""})),r.forEach((e=>{const t=e.closest(".form-group")||e.parentNode;e.parentNode;if("date"==e.type){l="Please Select Date",e.style.border="";e.value.trim()||(o=!1,e.style.border="1px solid red",addErrorMessage(t,l))}else l="comments"==e.name?"Please Enter Comments":"email"==e.type?"Please Enter Email":"password"==e.type?"Please Enter Password":"This Field is Required.";const r=e.getAttribute("data-kilvish-name");let a;if(l=`${r||"This"} Field is Required.`,("tel"===e.type||e.hasAttribute("data-kilvish-tel"))&&(a=isKiltelEmpty(e),a&&(l=`${r||"Phone"} is required (enter full number, not just country code).`)),a)return o=!1,e.style.border="1px solid red",void addErrorMessage(e,l);e.value.trim()||(o=!1,e.style.border="1px solid red",addErrorMessage(t,l))})),a.length>0){const e={};a.forEach((t=>{const r=t.name;e[r]||(e[r]={isSelected:!1,groupElement:t.closest(".form-group")||t.closest(".mb-3")||t.closest(".form-check")||t.closest(".radios")||t.closest(".col-md-6")}),t.checked&&(e[r].isSelected=!0)})),Object.entries(e).forEach((([e,t])=>{if(!t.isSelected){o=!1;const r="Please select one option.";if(!t.groupElement)return void console.error("Invalid group element for radio group:",e);addErrorMessage(t.groupElement,r)}}))}return Object.keys(n).forEach((e=>{const t=n[e];if(t.some((e=>e.hasAttribute("data-ignore-kilvish"))))return;if(!t.some((e=>e.checked))){o=!1;const r=s.has(e)?"Please check this box to proceed":"Please select at least one option.";addErrorMessage(t[0].closest(".form-group")||t[0].closest(".form-check")||t[0].closest(".checkbox-container")||t[0].closest(".some-other-container"),r)}})),o}function addRealTimeValidation(e){const t=document.getElementById(e),r=t.querySelectorAll("input[required], select[required], textarea[required]"),a=(e,r=!0)=>{let a=t.querySelector(`label[for='${e.name}']`);if(!a){const t=e.closest("fieldset");t&&(a=t.querySelector("legend"))}a&&(r&&!a.innerHTML.includes("*")?a.innerHTML+=' <span style="color:red;">*</span>':!r&&a.innerHTML.includes("*")&&(a.innerHTML=a.innerHTML.replace(' <span style="color:red;">*</span>',"")))};r.forEach((e=>{const t=()=>{e.value.trim()?(!function(e){const t=e.form||e.closest("form");if(!t)return;const r=e.nextElementSibling;let a=e,n="afterend",s=e.name||e.id||"field";"SELECT"===e.tagName&&r&&(r.classList.contains("select2")||r.classList.contains("select2-container"))?(a=r,n="afterend",s=e.name||e.id||"select"):e.parentElement&&e.parentElement.classList.contains("input-group")&&(a=e.parentElement,n="afterend",s=e.name||e.id||"inputgroup");const o=t.querySelector(`#kil_err_${String(s).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);o&&(o.textContent="",o.classList.add("is-hidden")),e.style.border="",hideStarFor(e)}(e),a(e,!1)):a(e,!0)};e.addEventListener("input",t),e.addEventListener("change",t)}));const n=t.querySelectorAll('input[type="radio"]');[...new Set(Array.from(n).map((e=>e.name)))].forEach((e=>{const r=t.querySelectorAll(`input[type="radio"][name="${e}"]`);r.forEach((e=>{e.addEventListener("change",(()=>{if(Array.from(r).some((e=>e.checked))){const t=e.closest(".form-group")||e.closest(".form-check")||e.closest(".radios")||e.closest(".mb-3")||e.closest(".col-md-6"),r=t?.querySelector(".error-message");r&&r.remove()}}))}))}));const s=t.querySelectorAll('input[type="checkbox"]');[...new Set(Array.from(s).map((e=>e.name)))].forEach((e=>{const r=t.querySelectorAll(`input[type="checkbox"][name="${e}"]`);r.forEach((e=>{e.addEventListener("change",(()=>{if(Array.from(r).some((e=>e.checked))){const t=e.closest(".form-group")||e.closest(".form-check")||e.closest(".checkbox-container")||e.closest(".some-other-container"),r=t?.querySelector(".error-message");r&&r.remove()}}))}))}))}function validateForm(e){validateRequiredFields(e)||event.preventDefault()}function normalizeRequiredStars(e=document){e.querySelectorAll("label, legend").forEach((e=>{e.querySelectorAll("span").forEach((e=>{e.classList.contains("kil-required-star")||"*"!==e.textContent.trim()||e.remove()}));const t=e.querySelectorAll(".kil-required-star");for(let e=1;e<t.length;e++)t[e].remove()}))}function addAsteriskToRequiredFields_working(){document.querySelectorAll("input, select, textarea").forEach((e=>{if(e.required){let t;if(t=document.querySelector(`label[for='${e.name}']`),!t){const r=e.closest("fieldset");r&&(t=r.querySelector("legend"))}t&&!t.innerHTML.includes("*")&&(t.innerHTML+=' <span style="color:red;">*</span>')}}))}function addAsteriskToRequiredFields(){document.querySelectorAll("input[required], select[required], textarea[required]").forEach(ensureStarVisibleFor)}function attachInputEvents(){document.querySelectorAll("input, select, textarea").forEach((e=>{e.hasAttribute("data-ignore-kilvish")||(e.addEventListener("keyup",validateKilvishInput),e.addEventListener("change",validateKilvishInput))}))}function addValidateFormToSubmitButtons(){document.querySelectorAll("form").forEach((e=>{const t=e.id;if(t){e.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((e=>{e.setAttribute("onclick",`validateForm('#${t}')`)}))}else console.warn("Form without ID found. Skipping validation.")}))}function validateKilvishInput(e){const t=e.target;function r(e){const t=e.form||e.closest("form");if(!t)return;const r=e.nextElementSibling;let a=e.name||e.id||"field";"SELECT"===e.tagName&&r&&(r.classList.contains("select2")||r.classList.contains("select2-container"))?a=e.name||e.id||"select":e.parentElement&&e.parentElement.classList.contains("input-group")&&(a=e.name||e.id||"inputgroup");const n=t.querySelector(`#kil_err_${String(a).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);n&&(n.textContent="",n.classList.add("is-hidden")),e.style.border=""}let a=/^[a-zA-Z\s]*$/,n=!1;const s={image:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],doc:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pdf:["application/pdf"],mix:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],only_pdf_image:["application/pdf","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],only_doc_image:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"]},o={image:"Image",doc:"Document",pdf:"PDF",mix:"Image & Document",only_pdf_image:"PDF & Image",only_doc_image:"Document & Image"};if(r(t),"description"===t.name||"address"===t.name){if(n=!0,a=/^[a-zA-Z0-9@,._\s-'"*]*$/,t.value.length>400)return addErrorMessage(t,"Input exceeds the maximum length of 400 characters!"),t.style.border="1px solid red",void(t.value=t.value.substring(0,400))}else if("firstname"===t.name||"lastname"===t.name||"appointment_by"===t.name){n=!0,a=/^[a-zA-Z\s-]*$/;const r=/^[a-zA-Z0-9._@-\s]+$/,s=t.value;if(r.test(s)&&(s.length>20||s.length<2))return addErrorMessage(t,"This Field Must Be Between 2 And 20 Characters."),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("otp"===t.name){n=!0,a=/^\d{6}$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&6!==s.length)return addErrorMessage(t,"OTP must be exactly 6 digits"),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("number_of_items"===t.name){n=!0,a=/^\d{0,6}(\.\d{0,2})?$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&s.length>3)return addErrorMessage(t,"Pacakge Number Cannot Be Exceed 3 Digits"),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("contact"===t.name||"agent_contact"===t.id||"fullcontact"===t.name)n=!0,a=/^[\d\-\s]{0,20}$/;else if("number"===t.type){n=!0,a=/^\d{0,20}$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&(s.length>20||s.length<1))return addErrorMessage(t,"This Must Be Between 1 And 20 Digits."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("tel"===t.type){n=!0;let r=t.value.trim().replace(/\s+/g,"");t.value=r;if(a=/^\+?\d{7,15}$/,!/^\+?\d{7,15}$/.test(r))return addErrorMessage(t,"Enter a valid phone number (7–15 digits, optional +)."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("kildate"===t.name){n=!0,a=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=t.value.trim(),s=new Date(r.replace(/[-\/]/g,"/")),o=new Date;o.setHours(0,0,0,0);const l=t.getAttribute("data-kilvish-date");if(l){const[r,a]=l.replace("_","").split("_").map(Number),n=new Date(o),i=new Date(o);if(n.setFullYear(o.getFullYear()-r),i.setFullYear(o.getFullYear()-a),s>n||s<i)return addErrorMessage(t,`Birthday cannot be less than ${r} years ago or more than ${a} years in the future.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(s<o)return addErrorMessage(t,"The date cannot be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else{if("date"===t.type||"month"===t.type){n=!0,a=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=t.value.trim(),s="month"===t.type?new Date(r+"-01"):new Date(r.replace(/[-\/]/g,"/")),o=new Date;o.setHours(0,0,0,0);const l=t.getAttribute("data-kilvish-date");if(l)if(/^_(\d+)_(\d+)$/.test(l)){const[r,a]=l.replace("_","").split("_").map(Number),n=new Date(o),i=new Date(o);if(n.setFullYear(o.getFullYear()-r),i.setFullYear(o.getFullYear()-a),s>n||s<i)return addErrorMessage(t,`Age must be between ${r} and ${a} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^_(\d+)$/.test(l)){const r=Number(l.replace("_","")),a=new Date(o);if(a.setFullYear(o.getFullYear()-r),s.getTime()!==a.getTime())return addErrorMessage(t,`You must be exactly ${r} years old.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/future/.test(l)){if("future"===l&&s<=o)return addErrorMessage(t,"The selected date must be in the future."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("today_future"===l&&s<o)return addErrorMessage(t,"The selected date cannot be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/(\d+)_days_future/.test(l)){const r=Number(l.match(/(\d+)_days_future/)[1]),a=new Date(o);if(a.setDate(o.getDate()+r),s>a||s<o)return addErrorMessage(t,`The selected date must be within the next ${r} days.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_future$/.test(l)){const r=Number(l.match(/^(\d+)_years_future$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()+r),s<o||s>a)return addErrorMessage(t,`The date must be within the next ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_after$/.test(l)){const r=Number(l.match(/^(\d+)_years_after$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()+r),s.getTime()!==a.getTime())return addErrorMessage(t,`The date must be exactly ${r} years after today.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}else if(/past/.test(l)){if("past"===l&&s>=o)return addErrorMessage(t,"The selected date must be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/^(\d+)_years_past$/.test(l)){const r=Number(l.match(/^(\d+)_years_past$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()-r),s>o||s<a)return addErrorMessage(t,`The date must be within the past ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}else if(/^(\d+)_years_before$/.test(l)){const r=Number(l.match(/^(\d+)_years_before$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()-r),s>=a)return addErrorMessage(t,`The date must be before ${r} years ago.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_after$/.test(l)){const r=Number(l.match(/^(\d+)_years_after$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()+r),s<=a)return addErrorMessage(t,`The date must be after ${r} years from today.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/Between_(\d+)_(\d+)/.test(l)){const[r,a]=l.match(/Between_(\d+)_(\d+)/).slice(1,3).map(Number),n=new Date(r,0,1),o=new Date(a,11,31);if(s<n||s>o)return addErrorMessage(t,`The date must be between ${r} and ${a}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/from_(\d+)/.test(l)){const r=Number(l.match(/from_(\d+)/)[1]);if(s<new Date(r,0,1))return addErrorMessage(t,`The date must be from the year ${r} onwards.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/till_(\d+)/.test(l)){const r=Number(l.match(/till_(\d+)/)[1]);if(s>new Date(r,11,31))return addErrorMessage(t,`The date must be till the year ${r}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else{if("not_today"===l&&s.getTime()===o.getTime())return addErrorMessage(t,"Today's date is not allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("weekday"===l&&(0===s.getDay()||6===s.getDay()))return addErrorMessage(t,"Only weekdays (Monday to Friday) are allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("weekend"===l&&s.getDay()>=1&&s.getDay()<=5)return addErrorMessage(t,"Only weekends (Saturday and Sunday) are allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("first_of_month"===l&&1!==s.getDate())return addErrorMessage(t,"The date must be the first day of the month."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/^exact_(\d+)$/.test(l)){const r=Number(l.match(/^exact_(\d+)$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()-r),s.getTime()!==a.getTime())return addErrorMessage(t,`You must be exactly ${r} years old.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if("last_of_month"===l){const r=new Date(s.getFullYear(),s.getMonth()+1,0).getDate();if(s.getDate()!==r)return addErrorMessage(t,"The date must be the last day of the month."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}const i=t.getAttribute("data-kilvish-dategroup");if(i&&/.+_[12]$/.test(i)){const[r,a]=i.split("_"),n="1"===a?"2":"1",s=document.querySelector(`[data-kilvish-dategroup="${r}_${n}"]`);if(s&&s.value){const o="month"===t.type?new Date(t.value+"-01"):new Date(t.value.replace(/[-\/]/g,"/")),l="month"===s.type?new Date(s.value+"-01"):new Date(s.value.replace(/[-\/]/g,"/"));if(!("1"===a&&o<=l||"2"===a&&o>=l)){const o=t.dataset.kilvishDate_name||`Field (${r}_${a})`,l=s.dataset.kilvishDate_name||`Field (${r}_${n})`;return addErrorMessage(t,`${o} must be ${"1"===a?"before or same as":"after or same as"} ${l}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}}return void(t.style.border="")}if("age"===t.name){n=!0;const r=t.value.trim(),a=parseInt(r,10);if(isNaN(a))return addErrorMessage(t,"Please enter a valid number for age."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));const s=t.getAttribute("data-kilvish-age")||"18";if(/^(\d+)$/.test(s)){const r=Number(s);if(a!==r)return addErrorMessage(t,`Age must be exactly ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_(\d+)$/.test(s)){const[r,n]=s.split("_").map(Number);if(a<r)return addErrorMessage(t,`Minimum age must be ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(a>n)return addErrorMessage(t,`Age cannot exceed ${n} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}return void(t.style.border="")}}if("model_name"===t.name||"models[]"===t.name)n=!0,a=/^[a-zA-Z0-9]{4,20}$/;else if("email"===t.type){n=!0,a=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;const r=/^[a-zA-Z0-9._@-]+$/,s=t.value;if(r.test(s)&&!a.test(s))return addErrorMessage(t,"Invalid Email Format."),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}if(t.hasAttribute("data-kilvish-num")){n=!0;const r=t.value,s=t.getAttribute("data-kilvish-num");a=/^[0-9]*$/;let o=null,l=null;const i=s.match(/^_(\d+)_(\d+)$/);i&&(o=parseInt(i[1],10),l=parseInt(i[2],10));const d=s.match(/^exact_(\d+)$/),c=d?parseInt(d[1],10):null;/^\d*$/.test(r)?null!==c&&r.length!==c?(addErrorMessage(t,`This field must contain exactly ${c} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):o&&r.length<o||l&&r.length>l?(addErrorMessage(t,`This Field Must be between ${o} and ${l} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):t.style.border="":(addErrorMessage(t,"Only numerical characters are allowed."),t.style.border="2px solid red")}if(t.hasAttribute("data-kilvish-num11")){n=!0;const r=t.value,s=t.getAttribute("data-kilvish-num");a=/^[0-9]*$/;let o=null,l=null;const i=s?s.match(/^_(\d+)_(\d+)$/):null;i&&(o=parseInt(i[1],10),l=parseInt(i[2],10)),"exact_20"===s&&(a=/^[0-9]{20}$/),a.test(r)?o&&r.length<o||l&&r.length>l?(addErrorMessage(t,`This Field Must be between ${o} and ${l} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):t.style.border="":(addErrorMessage(t,"exact_20"===s?"This field must contain exactly 20 digits.":"Only numerical characters are allowed."),t.style.border="2px solid red")}if(t.hasAttribute("data-kilvish-char")){n=!0;const r=t.value,s=t.getAttribute("data-kilvish-char");if(s.startsWith("Yes")||s.startsWith("mix")){"mix"===s?a=/^[a-zA-Z0-9]*$/:"Yes"===s&&(a=/^[a-zA-Z]*$/);const n=s.split("_").slice(1).join("");if(n&&(a=new RegExp(`^[a-zA-Z0-9${n}]*$`)),!a.test(r))return addErrorMessage(t,"Invalid character entered!"),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}if(t.hasAttribute("data-kilvish-amount")){n=!0;const r=t.getAttribute("data-kilvish-amount");a=/^\d+(\.\d{0,2})?$/;let s="USD",o=null,l=null;const i=r.match(/^([A-Z]{3})(?:_(\d+)_(\d+))?$/);i&&(s=i[1],o=i[2]?parseFloat(i[2]):null,l=i[3]?parseFloat(i[3]):null),t.addEventListener("input",(()=>{let e=t.selectionStart,r=t.value;a.test(r)||(r=r.replace(/[^0-9.]/g,"").replace(/(\..*?)\..*/,"$1").replace(/(\.\d{2}).*/,"$1")),!r||r.includes(".")||r.endsWith(".")||(r=parseFloat(r).toFixed(2)),t.value=r;const n=r.indexOf(".");-1!==n&&e>n&&(e=Math.min(e,r.length)),t.setSelectionRange(e,e);let o=t.nextElementSibling;o&&o.classList.contains("amount-display")||(o=document.createElement("div"),o.className="amount-display",o.style.color="green",t.parentNode.insertBefore(o,t.nextSibling)),o.textContent=`${s} ${r||"0.00"} .`})),t.addEventListener("blur",(()=>{if(t.readOnly)return;let r=parseFloat(t.value||"0").toFixed(2),a=t.nextElementSibling;return null!==o&&r<o?(addErrorMessage(t,`Amount must be at least ${o.toFixed(2)} ${s}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value="",a&&(a.textContent="")))):null!==l&&r>l?(addErrorMessage(t,`Amount must not exceed ${l.toFixed(2)} ${s}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value="",a&&(a.textContent="")))):(t.style.border="",void(t.value=r))}))}if("password"===t.type){n=!0;const{bars:r,label:s,rulesUl:o}=ensurePassUI(t),l=t.getAttribute("data-kilvish-password")||"12",[i,d]=l.split("_"),c=parseInt(i,10)||12,u=parseInt(d||"128",10);a=new RegExp(`^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[\\W_]).{${c},${u}}$`);const p={length:`Password must be between ${c} and ${u} characters long`,uppercase:"At least one uppercase letter (A-Z)",lowercase:"At least one lowercase letter (a-z)",number:"At least one number (0-9)",special:"At least one special character (!@#$%^&*)",sequential:"No sequential characters (e.g., 1234, abcd)"},m={};Object.keys(p).forEach((e=>{let t=o.querySelector(`li[data-rule="${e}"]`);t||(t=document.createElement("li"),t.setAttribute("data-rule",e),t.textContent=`❌ ${p[e]}`,t.style.color="red",t.style.fontSize="12px",o.appendChild(t)),m[e]=t}));const g=e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1},y=e=>{let t=0;return e.length>=c&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),g(e)&&(t-=2),Math.max(0,t)},f=t.value||"",h={length:f.length>=c&&f.length<=u,uppercase:/[A-Z]/.test(f),lowercase:/[a-z]/.test(f),number:/\d/.test(f),special:/[\W_]/.test(f),sequential:!g(f)};Object.keys(h).forEach((e=>{const t=h[e];m[e].textContent=`${t?"✅":"❌"} ${p[e]}`,m[e].style.color=t?"green":"red"}));const b=y(f);r.forEach((e=>e.style.background="lightgray")),b<=2?(r[0]&&(r[0].style.background="red"),s.textContent="Weak",s.style.color="red"):b<=4?(r[0]&&(r[0].style.background="yellow"),r[1]&&(r[1].style.background="yellow"),s.textContent="Medium",s.style.color="orange"):(r[0]&&(r[0].style.background="green"),r[1]&&(r[1].style.background="green"),r[2]&&(r[2].style.background="green"),s.textContent="Strong",s.style.color="green");const v=a.test(f)&&Object.values(h).every(Boolean);return t.style.border=v?"1px solid green":"1px solid red",void(v||"change"!==e.type||(t.value=""))}if("file"===t.type){n=!0;const e=t.getAttribute("data-kilvish-file")||"image",[r,...a]=e.split("_"),l=s[e]||s[r]||s.image,i=t.files;let d=1,c=1/0;if(a.length>=2&&(d=parseInt(a[0],10),c=parseInt(a[1],10)),i.length<d||i.length>c)return addErrorMessage(t,`Please select between ${d} and ${c} valid file(s).`),t.value="",t.style.border="1px solid red",!1;const u=o[e]||r.toUpperCase();for(const e of i)if(!l.includes(e.type))return addErrorMessage(t,`Invalid file type. Allowed types: ${u}.`),t.value="",t.style.border="1px solid red",!1}else n&&("keyup"===e.type&&(a.test(t.value)||("password"!==t.type&&addErrorMessage(t,"Invalid character entered!"),t.style.border="1px solid red")),"change"===e.type&&(a.test(t.value)?(t.style.border="",r(t)):(t.value="",addErrorMessage(t,"Invalid character or format!"),t.style.border="1px solid red")))}function addErrorMessage_working(e,t){if(!e.querySelector(".error-message")){const r=document.createElement("div");r.className="error-message",r.style.color="red",r.style.fontSize="12px",r.innerText=t,e.appendChild(r)}}function addErrorMessage_working2(e,t){const r=e.form?e.form:e.closest("form");if(!r)return;const{anchor:a,mode:n,key:s}=getErrorAnchor(e),o=getOrCreateErrorNode(r,a,n,s);o.textContent=t||"",o.classList.remove("is-hidden")}function addErrorMessage(e,t){const r=e.form?e.form:e.closest("form");if(!r)return;let a=null;if(e&&e.tagName&&/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName))a=e;else if(e&&e.querySelector){const t=e.querySelectorAll("input,select,textarea");a=t.length?t[t.length-1]:null}let n=e,s="beforeend",o="container";if(a){const e=a.nextElementSibling;"SELECT"===a.tagName&&e&&(e.classList.contains("select2")||e.classList.contains("select2-container"))?(n=e,s="afterend",o=a.name||a.id||"select"):a.parentElement&&a.parentElement.classList.contains("input-group")?(n=a.parentElement,s="afterend",o=a.name||a.id||"inputgroup"):(n=a,s="afterend",o=a.name||a.id||"field")}const l=`kil_err_${String(o).replace(/[^a-zA-Z0-9_\-]/g,"_")}`;let i=r.querySelector(`#${l}`);if(i||(i=document.createElement("div"),i.id=l,i.className="error-message is-hidden","beforeend"===s?n.insertAdjacentElement("beforeend",i):n.insertAdjacentElement("afterend",i)),i.textContent=t||"",i.classList.remove("is-hidden"),a)ensureStarVisibleFor(a);else{const t=e.querySelector("input[required],select[required],textarea[required]")||e.querySelector("input,select,textarea");t&&ensureStarVisibleFor(t)}}function getFieldAnchorForUI(e){return e.parentElement&&e.parentElement.classList.contains("input-group")?e.parentElement:e}function ensurePassUI(e){const t=getFieldAnchorForUI(e),r=e.name||e.id||"password",a=`kil_passui_${String(r).replace(/[^a-zA-Z0-9_-]/g,"_")}`;let n=t.parentNode.querySelector(`#${a}`);if(!n){n=document.createElement("div"),n.id=a,n.className="kil-passui";const e=document.createElement("div");e.className="password-strength";const r=document.createElement("div");r.className="bars";const s=document.createElement("div");s.className="bar";const o=document.createElement("div");o.className="bar";const l=document.createElement("div");l.className="bar",r.append(s,o,l);const i=document.createElement("span");i.className="label",i.textContent="Weak",i.style.fontSize="12px",e.append(r,i);const d=document.createElement("ul");d.className="password-validation",n.append(e,d),t.insertAdjacentElement("afterend",n)}const s=n.querySelectorAll(".bar"),o=n.querySelector(".password-strength .label"),l=n.querySelector(".password-validation");return{wrap:n,bars:s,label:o,rulesUl:l}}function getEyeAnchor(e){const t=e.closest(".input-group");if(t)return t.classList.add("kil-eye-rel"),e.classList.add("kil-eye-pad"),{anchor:t};if(!e.parentElement.classList.contains("kil-eye-wrap")){const t=document.createElement("span");t.className="kil-eye-wrap",e.parentNode.insertBefore(t,e),t.appendChild(e)}return e.classList.add("kil-eye-pad"),{anchor:e.parentElement}}function ensureEyeForPassword(e){if("1"===e.dataset.kileyeAttached)return;if(e.hasAttribute("data-kileye-false"))return;const{anchor:t}=getEyeAnchor(e);t.style.overflow="visible";let r=t.querySelector(".kil-eye-btn");r||(r=document.createElement("button"),r.type="button",r.className="kil-eye-btn",r.setAttribute("tabindex","-1"),r.setAttribute("aria-label","Show/Hide password"),r.innerHTML='<i class="fa fa-eye-slash" aria-hidden="true"></i>',t.appendChild(r));const a=e.getAttribute("data-kileye-color");a&&(r.style.color=a);const n=()=>r.querySelector("i");function s(){e.type="text",n()&&(n().classList.remove("fa-eye-slash"),n().classList.add("fa-eye"))}function o(){e.type="password",n()&&(n().classList.remove("fa-eye"),n().classList.add("fa-eye-slash"))}function l(){"password"===e.type?s():o()}const i=(e.getAttribute("data-kileye-show")||"hold").toLowerCase(),d=(e.getAttribute("data-kileye-initial")||"auto").toLowerCase();"fix"===i||"on"===d?s():"off"!==d&&"auto"!==d||o(),r.onmousedown=r.onmouseup=r.onmouseleave=r.onclick=null,r.ontouchstart=r.ontouchend=r.ontouchcancel=null,"toggle"===i||"fix"===i?(r.onclick=e=>{e.preventDefault(),l()},r.addEventListener("touchstart",(e=>{e.preventDefault(),l()}),{passive:!1})):(r.onmousedown=e=>{e.preventDefault(),s()},r.onmouseup=()=>o(),r.onmouseleave=()=>o(),r.onblur=()=>o(),r.addEventListener("touchstart",(e=>{e.preventDefault(),s()}),{passive:!1}),r.addEventListener("touchend",(()=>o())),r.addEventListener("touchcancel",(()=>o()))),e.addEventListener("blur",(()=>{"hold"===i&&o()})),e.dataset.kileyeAttached="1"}!function(){if(document.getElementById("kil-req-style"))return;const e=document.createElement("style");e.id="kil-req-style",e.textContent="\n .kil-required-star{ color:#d32f2f; margin-left:2px; }\n .error-message{ display:block; min-height:16px; margin-top:4px; font-size:12px; color:#d32f2f; line-height:1.25; opacity:1; transition:opacity .12s ease; }\n .error-message.is-hidden{ opacity:0; }\n ",document.head.appendChild(e)}(),document.addEventListener("DOMContentLoaded",(()=>{normalizeRequiredStars(),addAsteriskToRequiredFields()})),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll("form").forEach((e=>{const t=e.id;t?addRealTimeValidation(t):console.warn("Form without ID found. Skipping validation.")})),attachInputEvents(),addAsteriskToRequiredFields(),addValidateFormToSubmitButtons()})),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll("input[type='password']").forEach((e=>{if(e.hasAttribute("data-ignore-kilvish"))return;const{bars:t,label:r}=ensurePassUI(e),a=e.getAttribute("data-kilvish-password")||"12",[n]=a.split("_").map(Number);e.addEventListener("input",(e=>{const a=(e=>{let t=0;return e.length>=n&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),(e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1})(e)&&(t-=2),Math.max(0,t)})(e.target.value);t.forEach((e=>e.style.background="lightgray")),a<=2?(t[0].style.background="red",r.textContent="Weak",r.style.color="red"):a<=4?(t[0].style.background="yellow",t[1].style.background="yellow",r.textContent="Medium",r.style.color="orange"):(t[0].style.background="green",t[1].style.background="green",t[2].style.background="green",r.textContent="Strong",r.style.color="green")}))}))})),function(){if(document.getElementById("kil-pass-style"))return;const e=document.createElement("style");e.id="kil-pass-style",e.textContent="\n .kil-passui { display:block; width:100%; margin-top:6px; }\n .kil-passui .password-strength { display:flex; align-items:center; gap:10px; }\n .kil-passui .password-strength .bars { display:flex; gap:4px; }\n .kil-passui .password-strength .bar { height:5px; width:30px; border-radius:3px; background:lightgray; }\n .kil-passui .password-validation { list-style:none; padding:0; margin:6px 0 0; }\n .kil-passui .password-validation li { font-size:12px; margin:2px 0; }\n ",document.head.appendChild(e)}(),function(){if(document.getElementById("kil-eye-style"))return;const e=document.createElement("style");e.id="kil-eye-style",e.textContent="\n .kil-eye-rel { position: relative !important; overflow: visible !important; }\n .kil-eye-wrap{ position:relative; display:block; }\n .kil-eye-btn{\n position:absolute; top:50%; right:10px; transform:translateY(-50%);\n display:inline-flex; align-items:center; justify-content:center;\n background:transparent; border:0; padding:0; margin:0;\n height:auto; width:auto; line-height:1; cursor:pointer; outline:none;\n z-index: 10; /* <-- stays above focused input */\n pointer-events: auto;\n }\n .kil-eye-btn i{ font-size:16px; }\n .kil-eye-pad { padding-right: 38px !important; }\n .kil-eye-btn { flex: 0 0 auto; }\n ",document.head.appendChild(e)}(),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll('input[type="password"]').forEach(ensureEyeForPassword)}));const _kilEyeObserver=new MutationObserver((e=>{for(const t of e)t.addedNodes&&t.addedNodes.forEach((e=>{e instanceof HTMLElement&&(e.matches&&e.matches('input[type="password"]')&&ensureEyeForPassword(e),e.querySelectorAll&&e.querySelectorAll('input[type="password"]').forEach(ensureEyeForPassword))}))}));_kilEyeObserver.observe(document.documentElement,{childList:!0,subtree:!0});
|
|
1
|
+
!function(){if(document.getElementById("kil-error-style"))return;const e=document.createElement("style");e.id="kil-error-style",e.textContent="\n .error-message {\n display:block;\n min-height:16px; /* reserves space even when empty */\n margin-top:4px;\n font-size:12px;\n color:#d32f2f;\n line-height:1.25;\n opacity:1;\n transition: opacity .12s ease;\n }\n .error-message.is-hidden{ opacity:0; }\n ",document.head.appendChild(e)}();const _escKey=e=>String(e||"").replace(/[^a-zA-Z0-9_\-]/g,"_");function getErrorAnchor(e){let t=null;if(e&&e.tagName&&/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName))t=e;else if(e&&e.querySelector){const r=e.querySelectorAll("input,select,textarea");t=r.length?r[r.length-1]:null}if(!t)return{anchor:e,mode:"beforeend",key:"container"};const r=t.nextElementSibling;return"SELECT"===t.tagName&&r&&(r.classList.contains("select2")||r.classList.contains("select2-container"))?{anchor:r,mode:"afterend",key:t.name||t.id||"select"}:t.parentElement&&t.parentElement.classList.contains("input-group")?{anchor:t.parentElement,mode:"afterend",key:t.name||t.id||"inputgroup"}:{anchor:t,mode:"afterend",key:t.name||t.id||"field"}}function getOrCreateErrorNode(e,t,r,a){const s=`kil_err_${_escKey(a)}`;let n=e.querySelector(`#${s}`);return n||(n=document.createElement("div"),n.id=s,n.className="error-message is-hidden","beforeend"===r?t.insertAdjacentElement("beforeend",n):t.insertAdjacentElement("afterend",n)),n}function findLabelFor(e){if(!e)return null;const t=e.form||document;let r=null;if(e.id&&(r=t.querySelector(`label[for="${CSS.escape(e.id)}"]`)),!r&&e.name&&(r=t.querySelector(`label[for="${CSS.escape(e.name)}"]`)),r||(r=e.closest("label")),!r){const t=e.closest("fieldset");t&&(r=t.querySelector("legend"))}return r}function ensureStarVisibleFor(e){const t=findLabelFor(e);if(!t)return;let r=t.querySelector(".kil-required-star");r||(r=document.createElement("span"),r.className="kil-required-star",r.textContent=" *",t.appendChild(r)),r.style.visibility="visible"}function hideStarFor(e){const t=findLabelFor(e);if(!t)return;const r=t.querySelector(".kil-required-star");r&&(r.style.visibility="hidden")}function isKiltelEmpty(e){const t=e.closest(".kiltel-phone-wrap")||e.parentElement,r=t&&(t.querySelector('input[name="contact"]')||t.querySelector("#contact"));if(r){return(r.value||"").replace(/\D/g,"").length<7}const a=(e.value||"").trim().replace(/\s|-/g,"");if(!a)return!0;if(/^\+?$/.test(a))return!0;if(/^\+?\d{1,4}$/.test(a))return!0;return a.replace(/\D/g,"").length<7}function validateRequiredFields(e){const t=document.querySelector(`${e}`),r=t.querySelectorAll("input[required], select[required], textarea[required]"),a=(t.querySelectorAll("fieldset.radios"),t.querySelectorAll('input[type="radio"]')),s={},n=new Set;t.querySelectorAll('input[type="checkbox"]').forEach((e=>{const t=e.name;s[t]||(s[t]=[]),s[t].push(e),e.hasAttribute("required")&&n.add(t)}));t.querySelectorAll(".select2");let o=!0,l="This Field is Required.";if(t.querySelectorAll(".error-message").forEach((e=>{e.textContent="",e.classList.add("is-hidden")})),r.forEach((e=>{e.style.border=""})),r.forEach((e=>{const t=e.closest(".form-group")||e.parentNode;e.parentNode;if("date"==e.type){l="Please Select Date",e.style.border="";e.value.trim()||(o=!1,e.style.border="1px solid red",addErrorMessage(t,l))}else l="comments"==e.name?"Please Enter Comments":"email"==e.type?"Please Enter Email":"password"==e.type?"Please Enter Password":"This Field is Required.";const r=e.getAttribute("data-kilvish-name");let a;if(l=`${r||"This"} Field is Required.`,("tel"===e.type||e.hasAttribute("data-kilvish-tel"))&&(a=isKiltelEmpty(e),a&&(l=`${r||"Phone"} is required (enter full number, not just country code).`)),a)return o=!1,e.style.border="1px solid red",void addErrorMessage(e,l);e.value.trim()||(o=!1,e.style.border="1px solid red",addErrorMessage(t,l))})),a.length>0){const e={};a.forEach((t=>{const r=t.name;e[r]||(e[r]={isSelected:!1,groupElement:t.closest(".form-group")||t.closest(".mb-3")||t.closest(".form-check")||t.closest(".radios")||t.closest(".col-md-6")}),t.checked&&(e[r].isSelected=!0)})),Object.entries(e).forEach((([e,t])=>{if(!t.isSelected){o=!1;const r="Please select one option.";if(!t.groupElement)return void console.error("Invalid group element for radio group:",e);addErrorMessage(t.groupElement,r)}}))}return Object.keys(s).forEach((e=>{const t=s[e];if(t.some((e=>e.hasAttribute("data-ignore-kilvish"))))return;if(!t.some((e=>e.checked))){o=!1;const r=n.has(e)?"Please check this box to proceed":"Please select at least one option.";addErrorMessage(t[0].closest(".form-group")||t[0].closest(".form-check")||t[0].closest(".checkbox-container")||t[0].closest(".some-other-container"),r)}})),o}function addRealTimeValidation(e){const t=document.getElementById(e),r=t.querySelectorAll("input[required], select[required], textarea[required]"),a=(e,r=!0)=>{let a=t.querySelector(`label[for='${e.name}']`);if(!a){const t=e.closest("fieldset");t&&(a=t.querySelector("legend"))}a&&(r&&!a.innerHTML.includes("*")?a.innerHTML+=' <span style="color:red;">*</span>':!r&&a.innerHTML.includes("*")&&(a.innerHTML=a.innerHTML.replace(' <span style="color:red;">*</span>',"")))};r.forEach((e=>{const t=()=>{e.value.trim()?(!function(e){const t=e.form||e.closest("form");if(!t)return;const r=e.nextElementSibling;let a=e,s="afterend",n=e.name||e.id||"field";"SELECT"===e.tagName&&r&&(r.classList.contains("select2")||r.classList.contains("select2-container"))?(a=r,s="afterend",n=e.name||e.id||"select"):e.parentElement&&e.parentElement.classList.contains("input-group")&&(a=e.parentElement,s="afterend",n=e.name||e.id||"inputgroup");const o=t.querySelector(`#kil_err_${String(n).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);o&&(o.textContent="",o.classList.add("is-hidden")),e.style.border="",hideStarFor(e)}(e),a(e,!1)):a(e,!0)};e.addEventListener("input",t),e.addEventListener("change",t)}));const s=t.querySelectorAll('input[type="radio"]');[...new Set(Array.from(s).map((e=>e.name)))].forEach((e=>{const r=t.querySelectorAll(`input[type="radio"][name="${e}"]`);r.forEach((e=>{e.addEventListener("change",(()=>{if(Array.from(r).some((e=>e.checked))){const t=e.closest(".form-group")||e.closest(".form-check")||e.closest(".radios")||e.closest(".mb-3")||e.closest(".col-md-6"),r=t?.querySelector(".error-message");r&&r.remove()}}))}))}));const n=t.querySelectorAll('input[type="checkbox"]');[...new Set(Array.from(n).map((e=>e.name)))].forEach((e=>{const r=t.querySelectorAll(`input[type="checkbox"][name="${e}"]`);r.forEach((e=>{e.addEventListener("change",(()=>{if(Array.from(r).some((e=>e.checked))){const t=e.closest(".form-group")||e.closest(".form-check")||e.closest(".checkbox-container")||e.closest(".some-other-container"),r=t?.querySelector(".error-message");r&&r.remove()}}))}))}))}function validateForm(e){validateRequiredFields(e)||event.preventDefault()}function normalizeRequiredStars(e=document){e.querySelectorAll("label, legend").forEach((e=>{e.querySelectorAll("span").forEach((e=>{e.classList.contains("kil-required-star")||"*"!==e.textContent.trim()||e.remove()}));const t=e.querySelectorAll(".kil-required-star");for(let e=1;e<t.length;e++)t[e].remove()}))}function addAsteriskToRequiredFields_working(){document.querySelectorAll("input, select, textarea").forEach((e=>{if(e.required){let t;if(t=document.querySelector(`label[for='${e.name}']`),!t){const r=e.closest("fieldset");r&&(t=r.querySelector("legend"))}t&&!t.innerHTML.includes("*")&&(t.innerHTML+=' <span style="color:red;">*</span>')}}))}function addAsteriskToRequiredFields(){document.querySelectorAll("input[required], select[required], textarea[required]").forEach(ensureStarVisibleFor)}function attachInputEvents(){document.querySelectorAll("input, select, textarea").forEach((e=>{e.hasAttribute("data-ignore-kilvish")||(e.addEventListener("keyup",validateKilvishInput),e.addEventListener("change",validateKilvishInput))}))}function addValidateFormToSubmitButtons(){document.querySelectorAll("form").forEach((e=>{const t=e.id;if(t){e.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((e=>{e.setAttribute("onclick",`validateForm('#${t}')`)}))}else console.warn("Form without ID found. Skipping validation.")}))}function validateKilvishInput(e){const t=e.target;function r(e){const t=e.form||e.closest("form");if(!t)return;const r=e.nextElementSibling;let a=e.name||e.id||"field";"SELECT"===e.tagName&&r&&(r.classList.contains("select2")||r.classList.contains("select2-container"))?a=e.name||e.id||"select":e.parentElement&&e.parentElement.classList.contains("input-group")&&(a=e.name||e.id||"inputgroup");const s=t.querySelector(`#kil_err_${String(a).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);s&&(s.textContent="",s.classList.add("is-hidden")),e.style.border=""}let a=/^[a-zA-Z\s]*$/;const s=t.hasAttribute("data-kilvish-num")||t.hasAttribute("data-kilvish-num11")||t.hasAttribute("data-kilvish-char")||t.hasAttribute("data-kilvish-amount")||t.hasAttribute("data-kilvish-date")||t.hasAttribute("data-kilvish-dategroup")||t.hasAttribute("data-kilvish-age")||t.hasAttribute("data-kilvish-file")||t.hasAttribute("data-kilvish-password"),n=t.hasAttribute("data-kilvish-default")||t.form&&t.form.hasAttribute("data-kilvish-default");let o=n;const l={image:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],doc:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pdf:["application/pdf"],mix:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],only_pdf_image:["application/pdf","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],only_doc_image:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"]},i={image:"Image",doc:"Document",pdf:"PDF",mix:"Image & Document",only_pdf_image:"PDF & Image",only_doc_image:"Document & Image"};if(r(t),s||n){if("description"===t.name||"address"===t.name){if(o=!0,a=/^[a-zA-Z0-9@,._\s-'"*]*$/,t.value.length>400)return addErrorMessage(t,"Input exceeds the maximum length of 400 characters!"),t.style.border="1px solid red",void(t.value=t.value.substring(0,400))}else if("firstname"===t.name||"lastname"===t.name||"appointment_by"===t.name){o=!0,a=/^[a-zA-Z\s-]*$/;const r=/^[a-zA-Z0-9._@-\s]+$/,s=t.value;if(r.test(s)&&(s.length>20||s.length<2))return addErrorMessage(t,"This Field Must Be Between 2 And 20 Characters."),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("otp"===t.name){o=!0,a=/^\d{6}$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&6!==s.length)return addErrorMessage(t,"OTP must be exactly 6 digits"),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("number_of_items"===t.name){o=!0,a=/^\d{0,6}(\.\d{0,2})?$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&s.length>3)return addErrorMessage(t,"Pacakge Number Cannot Be Exceed 3 Digits"),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("contact"===t.name||"agent_contact"===t.id||"fullcontact"===t.name)o=!0,a=/^[\d\-\s]{0,20}$/;else if("number"===t.type){o=!0,a=/^\d{0,20}$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&(s.length>20||s.length<1))return addErrorMessage(t,"This Must Be Between 1 And 20 Digits."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("tel"===t.type){o=!0;let r=t.value.trim().replace(/\s+/g,"");t.value=r;if(a=/^\+?\d{7,15}$/,!/^\+?\d{7,15}$/.test(r))return addErrorMessage(t,"Enter a valid phone number (7–15 digits, optional +)."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("kildate"===t.name){o=!0,a=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=t.value.trim(),s=new Date(r.replace(/[-\/]/g,"/")),n=new Date;n.setHours(0,0,0,0);const l=t.getAttribute("data-kilvish-date");if(l){const[r,a]=l.replace("_","").split("_").map(Number),o=new Date(n),i=new Date(n);if(o.setFullYear(n.getFullYear()-r),i.setFullYear(n.getFullYear()-a),s>o||s<i)return addErrorMessage(t,`Birthday cannot be less than ${r} years ago or more than ${a} years in the future.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(s<n)return addErrorMessage(t,"The date cannot be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else{if("date"===t.type||"month"===t.type){o=!0,a=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=t.value.trim(),s="month"===t.type?new Date(r+"-01"):new Date(r.replace(/[-\/]/g,"/")),n=new Date;n.setHours(0,0,0,0);const l=t.getAttribute("data-kilvish-date");if(l)if(/^_(\d+)_(\d+)$/.test(l)){const[r,a]=l.replace("_","").split("_").map(Number),o=new Date(n),i=new Date(n);if(o.setFullYear(n.getFullYear()-r),i.setFullYear(n.getFullYear()-a),s>o||s<i)return addErrorMessage(t,`Age must be between ${r} and ${a} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^_(\d+)$/.test(l)){const r=Number(l.replace("_","")),a=new Date(n);if(a.setFullYear(n.getFullYear()-r),s.getTime()!==a.getTime())return addErrorMessage(t,`You must be exactly ${r} years old.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/future/.test(l)){if("future"===l&&s<=n)return addErrorMessage(t,"The selected date must be in the future."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("today_future"===l&&s<n)return addErrorMessage(t,"The selected date cannot be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/(\d+)_days_future/.test(l)){const r=Number(l.match(/(\d+)_days_future/)[1]),a=new Date(n);if(a.setDate(n.getDate()+r),s>a||s<n)return addErrorMessage(t,`The selected date must be within the next ${r} days.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_future$/.test(l)){const r=Number(l.match(/^(\d+)_years_future$/)[1]),a=new Date(n);if(a.setFullYear(n.getFullYear()+r),s<n||s>a)return addErrorMessage(t,`The date must be within the next ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_after$/.test(l)){const r=Number(l.match(/^(\d+)_years_after$/)[1]),a=new Date(n);if(a.setFullYear(n.getFullYear()+r),s.getTime()!==a.getTime())return addErrorMessage(t,`The date must be exactly ${r} years after today.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}else if(/past/.test(l)){if("past"===l&&s>=n)return addErrorMessage(t,"The selected date must be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/^(\d+)_years_past$/.test(l)){const r=Number(l.match(/^(\d+)_years_past$/)[1]),a=new Date(n);if(a.setFullYear(n.getFullYear()-r),s>n||s<a)return addErrorMessage(t,`The date must be within the past ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}else if(/^(\d+)_years_before$/.test(l)){const r=Number(l.match(/^(\d+)_years_before$/)[1]),a=new Date(n);if(a.setFullYear(n.getFullYear()-r),s>=a)return addErrorMessage(t,`The date must be before ${r} years ago.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_after$/.test(l)){const r=Number(l.match(/^(\d+)_years_after$/)[1]),a=new Date(n);if(a.setFullYear(n.getFullYear()+r),s<=a)return addErrorMessage(t,`The date must be after ${r} years from today.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/Between_(\d+)_(\d+)/.test(l)){const[r,a]=l.match(/Between_(\d+)_(\d+)/).slice(1,3).map(Number),n=new Date(r,0,1),o=new Date(a,11,31);if(s<n||s>o)return addErrorMessage(t,`The date must be between ${r} and ${a}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/from_(\d+)/.test(l)){const r=Number(l.match(/from_(\d+)/)[1]);if(s<new Date(r,0,1))return addErrorMessage(t,`The date must be from the year ${r} onwards.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/till_(\d+)/.test(l)){const r=Number(l.match(/till_(\d+)/)[1]);if(s>new Date(r,11,31))return addErrorMessage(t,`The date must be till the year ${r}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else{if("not_today"===l&&s.getTime()===n.getTime())return addErrorMessage(t,"Today's date is not allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("weekday"===l&&(0===s.getDay()||6===s.getDay()))return addErrorMessage(t,"Only weekdays (Monday to Friday) are allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("weekend"===l&&s.getDay()>=1&&s.getDay()<=5)return addErrorMessage(t,"Only weekends (Saturday and Sunday) are allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("first_of_month"===l&&1!==s.getDate())return addErrorMessage(t,"The date must be the first day of the month."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/^exact_(\d+)$/.test(l)){const r=Number(l.match(/^exact_(\d+)$/)[1]),a=new Date(n);if(a.setFullYear(n.getFullYear()-r),s.getTime()!==a.getTime())return addErrorMessage(t,`You must be exactly ${r} years old.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if("last_of_month"===l){const r=new Date(s.getFullYear(),s.getMonth()+1,0).getDate();if(s.getDate()!==r)return addErrorMessage(t,"The date must be the last day of the month."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}const i=t.getAttribute("data-kilvish-dategroup");if(i&&/.+_[12]$/.test(i)){const[r,a]=i.split("_"),s="1"===a?"2":"1",n=document.querySelector(`[data-kilvish-dategroup="${r}_${s}"]`);if(n&&n.value){const o="month"===t.type?new Date(t.value+"-01"):new Date(t.value.replace(/[-\/]/g,"/")),l="month"===n.type?new Date(n.value+"-01"):new Date(n.value.replace(/[-\/]/g,"/"));if(!("1"===a&&o<=l||"2"===a&&o>=l)){const o=t.dataset.kilvishDate_name||`Field (${r}_${a})`,l=n.dataset.kilvishDate_name||`Field (${r}_${s})`;return addErrorMessage(t,`${o} must be ${"1"===a?"before or same as":"after or same as"} ${l}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}}return void(t.style.border="")}if("age"===t.name){o=!0;const r=t.value.trim(),a=parseInt(r,10);if(isNaN(a))return addErrorMessage(t,"Please enter a valid number for age."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));const s=t.getAttribute("data-kilvish-age")||"18";if(/^(\d+)$/.test(s)){const r=Number(s);if(a!==r)return addErrorMessage(t,`Age must be exactly ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_(\d+)$/.test(s)){const[r,n]=s.split("_").map(Number);if(a<r)return addErrorMessage(t,`Minimum age must be ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(a>n)return addErrorMessage(t,`Age cannot exceed ${n} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}return void(t.style.border="")}}if("model_name"===t.name||"models[]"===t.name)o=!0,a=/^[a-zA-Z0-9]{4,20}$/;else if("email"===t.type){o=!0,a=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;const r=/^[a-zA-Z0-9._@-]+$/,s=t.value;if(r.test(s)&&!a.test(s))return addErrorMessage(t,"Invalid Email Format."),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}if(t.hasAttribute("data-kilvish-num")){o=!0;const r=t.value,s=t.getAttribute("data-kilvish-num");a=/^[0-9]*$/;let n=null,l=null;const i=s.match(/^_(\d+)_(\d+)$/);i&&(n=parseInt(i[1],10),l=parseInt(i[2],10));const d=s.match(/^exact_(\d+)$/),c=d?parseInt(d[1],10):null;/^\d*$/.test(r)?null!==c&&r.length!==c?(addErrorMessage(t,`This field must contain exactly ${c} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):n&&r.length<n||l&&r.length>l?(addErrorMessage(t,`This Field Must be between ${n} and ${l} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):t.style.border="":(addErrorMessage(t,"Only numerical characters are allowed."),t.style.border="2px solid red")}if(t.hasAttribute("data-kilvish-num11")){o=!0;const r=t.value,s=t.getAttribute("data-kilvish-num");a=/^[0-9]*$/;let n=null,l=null;const i=s?s.match(/^_(\d+)_(\d+)$/):null;i&&(n=parseInt(i[1],10),l=parseInt(i[2],10)),"exact_20"===s&&(a=/^[0-9]{20}$/),a.test(r)?n&&r.length<n||l&&r.length>l?(addErrorMessage(t,`This Field Must be between ${n} and ${l} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):t.style.border="":(addErrorMessage(t,"exact_20"===s?"This field must contain exactly 20 digits.":"Only numerical characters are allowed."),t.style.border="2px solid red")}if(t.hasAttribute("data-kilvish-char")){o=!0;const r=t.value,s=t.getAttribute("data-kilvish-char");if(s.startsWith("Yes")||s.startsWith("mix")){"mix"===s?a=/^[a-zA-Z0-9]*$/:"Yes"===s&&(a=/^[a-zA-Z]*$/);const n=s.split("_").slice(1).join("");if(n&&(a=new RegExp(`^[a-zA-Z0-9${n}]*$`)),!a.test(r))return addErrorMessage(t,"Invalid character entered!"),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}if(t.hasAttribute("data-kilvish-amount")){o=!0;const r=t.getAttribute("data-kilvish-amount");a=/^\d+(\.\d{0,2})?$/;let s="USD",n=null,l=null;const i=r.match(/^([A-Z]{3})(?:_(\d+)_(\d+))?$/);i&&(s=i[1],n=i[2]?parseFloat(i[2]):null,l=i[3]?parseFloat(i[3]):null),t.addEventListener("input",(()=>{let e=t.selectionStart,r=t.value;a.test(r)||(r=r.replace(/[^0-9.]/g,"").replace(/(\..*?)\..*/,"$1").replace(/(\.\d{2}).*/,"$1")),!r||r.includes(".")||r.endsWith(".")||(r=parseFloat(r).toFixed(2)),t.value=r;const n=r.indexOf(".");-1!==n&&e>n&&(e=Math.min(e,r.length)),t.setSelectionRange(e,e);let o=t.nextElementSibling;o&&o.classList.contains("amount-display")||(o=document.createElement("div"),o.className="amount-display",o.style.color="green",t.parentNode.insertBefore(o,t.nextSibling)),o.textContent=`${s} ${r||"0.00"} .`})),t.addEventListener("blur",(()=>{if(t.readOnly)return;let r=parseFloat(t.value||"0").toFixed(2),a=t.nextElementSibling;return null!==n&&r<n?(addErrorMessage(t,`Amount must be at least ${n.toFixed(2)} ${s}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value="",a&&(a.textContent="")))):null!==l&&r>l?(addErrorMessage(t,`Amount must not exceed ${l.toFixed(2)} ${s}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value="",a&&(a.textContent="")))):(t.style.border="",void(t.value=r))}))}if("password"===t.type){o=!0;const{bars:r,label:s,rulesUl:n}=ensurePassUI(t),l=t.getAttribute("data-kilvish-password")||"12",[i,d]=l.split("_"),c=parseInt(i,10)||12,u=parseInt(d||"128",10);a=new RegExp(`^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[\\W_]).{${c},${u}}$`);const p={length:`Password must be between ${c} and ${u} characters long`,uppercase:"At least one uppercase letter (A-Z)",lowercase:"At least one lowercase letter (a-z)",number:"At least one number (0-9)",special:"At least one special character (!@#$%^&*)",sequential:"No sequential characters (e.g., 1234, abcd)"},m={};Object.keys(p).forEach((e=>{let t=n.querySelector(`li[data-rule="${e}"]`);t||(t=document.createElement("li"),t.setAttribute("data-rule",e),t.textContent=`❌ ${p[e]}`,t.style.color="red",t.style.fontSize="12px",n.appendChild(t)),m[e]=t}));const g=e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1},y=e=>{let t=0;return e.length>=c&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),g(e)&&(t-=2),Math.max(0,t)},h=t.value||"",f={length:h.length>=c&&h.length<=u,uppercase:/[A-Z]/.test(h),lowercase:/[a-z]/.test(h),number:/\d/.test(h),special:/[\W_]/.test(h),sequential:!g(h)};Object.keys(f).forEach((e=>{const t=f[e];m[e].textContent=`${t?"✅":"❌"} ${p[e]}`,m[e].style.color=t?"green":"red"}));const b=y(h);r.forEach((e=>e.style.background="lightgray")),b<=2?(r[0]&&(r[0].style.background="red"),s.textContent="Weak",s.style.color="red"):b<=4?(r[0]&&(r[0].style.background="yellow"),r[1]&&(r[1].style.background="yellow"),s.textContent="Medium",s.style.color="orange"):(r[0]&&(r[0].style.background="green"),r[1]&&(r[1].style.background="green"),r[2]&&(r[2].style.background="green"),s.textContent="Strong",s.style.color="green");const v=a.test(h)&&Object.values(f).every(Boolean);return t.style.border=v?"1px solid green":"1px solid red",void(v||"change"!==e.type||(t.value=""))}if("file"===t.type){o=!0;const e=t.getAttribute("data-kilvish-file")||"image",[r,...a]=e.split("_"),s=l[e]||l[r]||l.image,n=t.files;let d=1,c=1/0;if(a.length>=2&&(d=parseInt(a[0],10),c=parseInt(a[1],10)),n.length<d||n.length>c)return addErrorMessage(t,`Please select between ${d} and ${c} valid file(s).`),t.value="",t.style.border="1px solid red",!1;const u=i[e]||r.toUpperCase();for(const e of n)if(!s.includes(e.type))return addErrorMessage(t,`Invalid file type. Allowed types: ${u}.`),t.value="",t.style.border="1px solid red",!1}else o&&("keyup"===e.type&&(a.test(t.value)||("password"!==t.type&&addErrorMessage(t,"Invalid character entered!"),t.style.border="1px solid red")),"change"===e.type&&(a.test(t.value)?(t.style.border="",r(t)):(t.value="",addErrorMessage(t,"Invalid character or format!"),t.style.border="1px solid red")))}}function addErrorMessage_working(e,t){if(!e.querySelector(".error-message")){const r=document.createElement("div");r.className="error-message",r.style.color="red",r.style.fontSize="12px",r.innerText=t,e.appendChild(r)}}function addErrorMessage_working2(e,t){const r=e.form?e.form:e.closest("form");if(!r)return;const{anchor:a,mode:s,key:n}=getErrorAnchor(e),o=getOrCreateErrorNode(r,a,s,n);o.textContent=t||"",o.classList.remove("is-hidden")}function addErrorMessage(e,t){const r=e.form?e.form:e.closest("form");if(!r)return;let a=null;if(e&&e.tagName&&/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName))a=e;else if(e&&e.querySelector){const t=e.querySelectorAll("input,select,textarea");a=t.length?t[t.length-1]:null}let s=e,n="beforeend",o="container";if(a){const e=a.nextElementSibling;"SELECT"===a.tagName&&e&&(e.classList.contains("select2")||e.classList.contains("select2-container"))?(s=e,n="afterend",o=a.name||a.id||"select"):a.parentElement&&a.parentElement.classList.contains("input-group")?(s=a.parentElement,n="afterend",o=a.name||a.id||"inputgroup"):(s=a,n="afterend",o=a.name||a.id||"field")}const l=`kil_err_${String(o).replace(/[^a-zA-Z0-9_\-]/g,"_")}`;let i=r.querySelector(`#${l}`);if(i||(i=document.createElement("div"),i.id=l,i.className="error-message is-hidden","beforeend"===n?s.insertAdjacentElement("beforeend",i):s.insertAdjacentElement("afterend",i)),i.textContent=t||"",i.classList.remove("is-hidden"),a)ensureStarVisibleFor(a);else{const t=e.querySelector("input[required],select[required],textarea[required]")||e.querySelector("input,select,textarea");t&&ensureStarVisibleFor(t)}}function getFieldAnchorForUI(e){return e.parentElement&&e.parentElement.classList.contains("input-group")?e.parentElement:e}function ensurePassUI(e){const t=getFieldAnchorForUI(e),r=e.name||e.id||"password",a=`kil_passui_${String(r).replace(/[^a-zA-Z0-9_-]/g,"_")}`;let s=t.parentNode.querySelector(`#${a}`);if(!s){s=document.createElement("div"),s.id=a,s.className="kil-passui";const e=document.createElement("div");e.className="password-strength";const r=document.createElement("div");r.className="bars";const n=document.createElement("div");n.className="bar";const o=document.createElement("div");o.className="bar";const l=document.createElement("div");l.className="bar",r.append(n,o,l);const i=document.createElement("span");i.className="label",i.textContent="Weak",i.style.fontSize="12px",e.append(r,i);const d=document.createElement("ul");d.className="password-validation",s.append(e,d),t.insertAdjacentElement("afterend",s)}const n=s.querySelectorAll(".bar"),o=s.querySelector(".password-strength .label"),l=s.querySelector(".password-validation");return{wrap:s,bars:n,label:o,rulesUl:l}}function getEyeAnchor(e){const t=e.closest(".input-group");if(t)return t.classList.add("kil-eye-rel"),e.classList.add("kil-eye-pad"),{anchor:t};if(!e.parentElement.classList.contains("kil-eye-wrap")){const t=document.createElement("span");t.className="kil-eye-wrap",e.parentNode.insertBefore(t,e),t.appendChild(e)}return e.classList.add("kil-eye-pad"),{anchor:e.parentElement}}function ensureEyeForPassword(e){if("1"===e.dataset.kileyeAttached)return;if(e.hasAttribute("data-kileye-false"))return;const{anchor:t}=getEyeAnchor(e);t.style.overflow="visible";let r=t.querySelector(".kil-eye-btn");r||(r=document.createElement("button"),r.type="button",r.className="kil-eye-btn",r.setAttribute("tabindex","-1"),r.setAttribute("aria-label","Show/Hide password"),r.innerHTML='<i class="fa fa-eye-slash" aria-hidden="true"></i>',t.appendChild(r));const a=e.getAttribute("data-kileye-color");a&&(r.style.color=a);const s=()=>r.querySelector("i");function n(){e.type="text",s()&&(s().classList.remove("fa-eye-slash"),s().classList.add("fa-eye"))}function o(){e.type="password",s()&&(s().classList.remove("fa-eye"),s().classList.add("fa-eye-slash"))}function l(){"password"===e.type?n():o()}const i=(e.getAttribute("data-kileye-show")||"hold").toLowerCase(),d=(e.getAttribute("data-kileye-initial")||"auto").toLowerCase();"fix"===i||"on"===d?n():"off"!==d&&"auto"!==d||o(),r.onmousedown=r.onmouseup=r.onmouseleave=r.onclick=null,r.ontouchstart=r.ontouchend=r.ontouchcancel=null,"toggle"===i||"fix"===i?(r.onclick=e=>{e.preventDefault(),l()},r.addEventListener("touchstart",(e=>{e.preventDefault(),l()}),{passive:!1})):(r.onmousedown=e=>{e.preventDefault(),n()},r.onmouseup=()=>o(),r.onmouseleave=()=>o(),r.onblur=()=>o(),r.addEventListener("touchstart",(e=>{e.preventDefault(),n()}),{passive:!1}),r.addEventListener("touchend",(()=>o())),r.addEventListener("touchcancel",(()=>o()))),e.addEventListener("blur",(()=>{"hold"===i&&o()})),e.dataset.kileyeAttached="1"}!function(){if(document.getElementById("kil-req-style"))return;const e=document.createElement("style");e.id="kil-req-style",e.textContent="\n .kil-required-star{ color:#d32f2f; margin-left:2px; }\n .error-message{ display:block; min-height:16px; margin-top:4px; font-size:12px; color:#d32f2f; line-height:1.25; opacity:1; transition:opacity .12s ease; }\n .error-message.is-hidden{ opacity:0; }\n ",document.head.appendChild(e)}(),document.addEventListener("DOMContentLoaded",(()=>{normalizeRequiredStars(),addAsteriskToRequiredFields()})),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll("form").forEach((e=>{const t=e.id;t?addRealTimeValidation(t):console.warn("Form without ID found. Skipping validation.")})),attachInputEvents(),addAsteriskToRequiredFields(),addValidateFormToSubmitButtons()})),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll("input[type='password']").forEach((e=>{if(e.hasAttribute("data-ignore-kilvish"))return;const{bars:t,label:r}=ensurePassUI(e),a=e.getAttribute("data-kilvish-password")||"12",[s]=a.split("_").map(Number);e.addEventListener("input",(e=>{const a=(e=>{let t=0;return e.length>=s&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),(e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1})(e)&&(t-=2),Math.max(0,t)})(e.target.value);t.forEach((e=>e.style.background="lightgray")),a<=2?(t[0].style.background="red",r.textContent="Weak",r.style.color="red"):a<=4?(t[0].style.background="yellow",t[1].style.background="yellow",r.textContent="Medium",r.style.color="orange"):(t[0].style.background="green",t[1].style.background="green",t[2].style.background="green",r.textContent="Strong",r.style.color="green")}))}))})),function(){if(document.getElementById("kil-pass-style"))return;const e=document.createElement("style");e.id="kil-pass-style",e.textContent="\n .kil-passui { display:block; width:100%; margin-top:6px; }\n .kil-passui .password-strength { display:flex; align-items:center; gap:10px; }\n .kil-passui .password-strength .bars { display:flex; gap:4px; }\n .kil-passui .password-strength .bar { height:5px; width:30px; border-radius:3px; background:lightgray; }\n .kil-passui .password-validation { list-style:none; padding:0; margin:6px 0 0; }\n .kil-passui .password-validation li { font-size:12px; margin:2px 0; }\n ",document.head.appendChild(e)}(),function(){if(document.getElementById("kil-eye-style"))return;const e=document.createElement("style");e.id="kil-eye-style",e.textContent="\n .kil-eye-rel { position: relative !important; overflow: visible !important; }\n .kil-eye-wrap{ position:relative; display:block; }\n .kil-eye-btn{\n position:absolute; top:50%; right:10px; transform:translateY(-50%);\n display:inline-flex; align-items:center; justify-content:center;\n background:transparent; border:0; padding:0; margin:0;\n height:auto; width:auto; line-height:1; cursor:pointer; outline:none;\n z-index: 10; /* <-- stays above focused input */\n pointer-events: auto;\n }\n .kil-eye-btn i{ font-size:16px; }\n .kil-eye-pad { padding-right: 38px !important; }\n .kil-eye-btn { flex: 0 0 auto; }\n ",document.head.appendChild(e)}(),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll('input[type="password"]').forEach(ensureEyeForPassword)}));const _kilEyeObserver=new MutationObserver((e=>{for(const t of e)t.addedNodes&&t.addedNodes.forEach((e=>{e instanceof HTMLElement&&(e.matches&&e.matches('input[type="password"]')&&ensureEyeForPassword(e),e.querySelectorAll&&e.querySelectorAll('input[type="password"]').forEach(ensureEyeForPassword))}))}));_kilEyeObserver.observe(document.documentElement,{childList:!0,subtree:!0});
|