kilvalidate 3.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.
@@ -697,8 +697,22 @@ function validateKilvishInput(event) {
697
697
  field.style.border = '';
698
698
  }
699
699
 
700
- // --- General valid character sets
701
- let validCharacters = /^[a-zA-Z\s]*$/; // only char, no special char no numbers
700
+ // --- General valid character sets
701
+ let validCharacters = /^[a-zA-Z\s]*$/; // only char, no special char no numbers
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;
702
716
 
703
717
  // Define allowed image/file types
704
718
  const validFilesTypes = {
@@ -719,12 +733,16 @@ function validateKilvishInput(event) {
719
733
  only_doc_image: 'Document & Image'
720
734
  };
721
735
 
722
- // --- class-agnostic cleanup (no container lookups)
723
- clearFieldError(inputField);
736
+ // --- class-agnostic cleanup (no container lookups)
737
+ clearFieldError(inputField);
738
+ if (!hasExplicitKilvishRule && !allowDefaultRules) {
739
+ return;
740
+ }
724
741
 
725
742
  // --- Custom validations by field/name/type
726
- if (inputField.name === 'description' || inputField.name === 'address') {
727
- validCharacters = /^[a-zA-Z0-9@,._\s-'"*]*$/;
743
+ if (inputField.name === 'description' || inputField.name === 'address') {
744
+ hasValidationRule = true;
745
+ validCharacters = /^[a-zA-Z0-9@,._\s-'"*]*$/;
728
746
  if (inputField.value.length > 400) {
729
747
  addErrorMessage(inputField, 'Input exceeds the maximum length of 400 characters!');
730
748
  inputField.style.border = '1px solid red';
@@ -732,8 +750,9 @@ function validateKilvishInput(event) {
732
750
  return;
733
751
  }
734
752
 
735
- } else if (inputField.name === 'firstname' || inputField.name === 'lastname' || inputField.name === 'appointment_by') {
736
- validCharacters = /^[a-zA-Z\s-]*$/; // allow hyphen
753
+ } else if (inputField.name === 'firstname' || inputField.name === 'lastname' || inputField.name === 'appointment_by') {
754
+ hasValidationRule = true;
755
+ validCharacters = /^[a-zA-Z\s-]*$/; // allow hyphen
737
756
  const allowedChars = /^[a-zA-Z0-9._@-\s]+$/;
738
757
  const inputValue = inputField.value;
739
758
  if (allowedChars.test(inputValue)) {
@@ -746,8 +765,9 @@ function validateKilvishInput(event) {
746
765
  }
747
766
  inputField.style.border = '';
748
767
 
749
- } else if (inputField.name === 'otp') {
750
- validCharacters = /^\d{6}$/;
768
+ } else if (inputField.name === 'otp') {
769
+ hasValidationRule = true;
770
+ validCharacters = /^\d{6}$/;
751
771
  const numericOnlyPattern = /^\d+$/;
752
772
  const inputValue = inputField.value;
753
773
  if (numericOnlyPattern.test(inputValue) && inputValue.length !== 6) {
@@ -758,8 +778,9 @@ function validateKilvishInput(event) {
758
778
  }
759
779
  inputField.style.border = '';
760
780
 
761
- } else if (inputField.name === 'number_of_items') {
762
- validCharacters = /^\d{0,6}(\.\d{0,2})?$/;
781
+ } else if (inputField.name === 'number_of_items') {
782
+ hasValidationRule = true;
783
+ validCharacters = /^\d{0,6}(\.\d{0,2})?$/;
763
784
  const numericOnlyPattern = /^\d+$/;
764
785
  const inputValue = inputField.value;
765
786
  if (numericOnlyPattern.test(inputValue) && inputValue.length > 3) {
@@ -770,11 +791,13 @@ function validateKilvishInput(event) {
770
791
  }
771
792
  inputField.style.border = '';
772
793
 
773
- } else if (inputField.name === 'contact' || inputField.id === 'agent_contact' || inputField.name === 'fullcontact' ) {
774
- validCharacters = /^[\d\-\s]{0,20}$/;
794
+ } else if (inputField.name === 'contact' || inputField.id === 'agent_contact' || inputField.name === 'fullcontact' ) {
795
+ hasValidationRule = true;
796
+ validCharacters = /^[\d\-\s]{0,20}$/;
775
797
 
776
- } else if (inputField.type === 'number') {
777
- validCharacters = /^\d{0,20}$/;
798
+ } else if (inputField.type === 'number') {
799
+ hasValidationRule = true;
800
+ validCharacters = /^\d{0,20}$/;
778
801
  const numericOnlyPattern = /^\d+$/;
779
802
  const inputValue = inputField.value;
780
803
  if (numericOnlyPattern.test(inputValue) && (inputValue.length > 20 || inputValue.length < 1)) {
@@ -785,8 +808,9 @@ function validateKilvishInput(event) {
785
808
  }
786
809
  inputField.style.border = '';
787
810
 
788
- } else if (inputField.type === 'tel') {
789
- let inputValue = inputField.value.trim().replace(/\s+/g, '');
811
+ } else if (inputField.type === 'tel') {
812
+ hasValidationRule = true;
813
+ let inputValue = inputField.value.trim().replace(/\s+/g, '');
790
814
  inputField.value = inputValue;
791
815
  const phonePattern = /^\+?\d{7,15}$/;
792
816
  validCharacters = /^\+?\d{7,15}$/;
@@ -798,8 +822,9 @@ function validateKilvishInput(event) {
798
822
  }
799
823
  inputField.style.border = '';
800
824
 
801
- } else if (inputField.name === 'kildate') {
802
- validCharacters = /^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;
825
+ } else if (inputField.name === 'kildate') {
826
+ hasValidationRule = true;
827
+ validCharacters = /^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;
803
828
  const inputValue = inputField.value.trim();
804
829
  const inputDate = new Date(inputValue.replace(/[-\/]/g, '/'));
805
830
  const today = new Date(); today.setHours(0,0,0,0);
@@ -825,8 +850,9 @@ function validateKilvishInput(event) {
825
850
  }
826
851
  inputField.style.border = '';
827
852
 
828
- } else if (inputField.type === 'date' || inputField.type === 'month') {
829
- validCharacters = /^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;
853
+ } else if (inputField.type === 'date' || inputField.type === 'month') {
854
+ hasValidationRule = true;
855
+ validCharacters = /^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;
830
856
  const inputValue = inputField.value.trim();
831
857
  const inputDate = (inputField.type === 'month')
832
858
  ? new Date(inputValue + '-01')
@@ -1020,8 +1046,9 @@ function validateKilvishInput(event) {
1020
1046
  inputField.style.border = '';
1021
1047
  return;
1022
1048
 
1023
- } else if (inputField.name === 'age') {
1024
- const inputValue = inputField.value.trim();
1049
+ } else if (inputField.name === 'age') {
1050
+ hasValidationRule = true;
1051
+ const inputValue = inputField.value.trim();
1025
1052
  const ageValue = parseInt(inputValue, 10);
1026
1053
  if (isNaN(ageValue)) {
1027
1054
  addErrorMessage(inputField, 'Please enter a valid number for age.');
@@ -1057,10 +1084,12 @@ function validateKilvishInput(event) {
1057
1084
  }
1058
1085
 
1059
1086
  // model_name / models[]
1060
- if (inputField.name === 'model_name' || inputField.name === 'models[]') {
1061
- validCharacters = /^[a-zA-Z0-9]{4,20}$/;
1062
- } else if (inputField.type === 'email') {
1063
- validCharacters = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
1087
+ if (inputField.name === 'model_name' || inputField.name === 'models[]') {
1088
+ hasValidationRule = true;
1089
+ validCharacters = /^[a-zA-Z0-9]{4,20}$/;
1090
+ } else if (inputField.type === 'email') {
1091
+ hasValidationRule = true;
1092
+ validCharacters = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
1064
1093
  const allowedEmailChars = /^[a-zA-Z0-9._@-]+$/;
1065
1094
  const inputValue = inputField.value;
1066
1095
  if (allowedEmailChars.test(inputValue) && !validCharacters.test(inputValue)) {
@@ -1073,8 +1102,9 @@ function validateKilvishInput(event) {
1073
1102
  }
1074
1103
 
1075
1104
  // data-kilvish-num
1076
- if (inputField.hasAttribute('data-kilvish-num')) {
1077
- const inputValue = inputField.value;
1105
+ if (inputField.hasAttribute('data-kilvish-num')) {
1106
+ hasValidationRule = true;
1107
+ const inputValue = inputField.value;
1078
1108
  const kilvishType = inputField.getAttribute('data-kilvish-num');
1079
1109
  validCharacters = /^[0-9]*$/;
1080
1110
  let min = null, max = null;
@@ -1100,8 +1130,9 @@ function validateKilvishInput(event) {
1100
1130
  }
1101
1131
 
1102
1132
  // data-kilvish-num11
1103
- if (inputField.hasAttribute('data-kilvish-num11')) {
1104
- const inputValue = inputField.value;
1133
+ if (inputField.hasAttribute('data-kilvish-num11')) {
1134
+ hasValidationRule = true;
1135
+ const inputValue = inputField.value;
1105
1136
  const kilvishType = inputField.getAttribute('data-kilvish-num');
1106
1137
  validCharacters = /^[0-9]*$/;
1107
1138
  let min = null, max = null;
@@ -1122,8 +1153,9 @@ function validateKilvishInput(event) {
1122
1153
  }
1123
1154
 
1124
1155
  // data-kilvish-char
1125
- if (inputField.hasAttribute('data-kilvish-char')) {
1126
- const inputValue = inputField.value;
1156
+ if (inputField.hasAttribute('data-kilvish-char')) {
1157
+ hasValidationRule = true;
1158
+ const inputValue = inputField.value;
1127
1159
  const charType = inputField.getAttribute('data-kilvish-char');
1128
1160
  if (charType.startsWith('Yes') || charType.startsWith('mix')) {
1129
1161
  if (charType === 'mix') validCharacters = /^[a-zA-Z0-9]*$/;
@@ -1141,6 +1173,7 @@ function validateKilvishInput(event) {
1141
1173
 
1142
1174
  // data-kilvish-amount
1143
1175
  if (inputField.hasAttribute('data-kilvish-amount')) {
1176
+ hasValidationRule = true;
1144
1177
  const kilvishType = inputField.getAttribute('data-kilvish-amount');
1145
1178
  validCharacters = /^\d+(\.\d{0,2})?$/;
1146
1179
  let currency = 'USD', minAmount = null, maxAmount = null;
@@ -1203,7 +1236,8 @@ function validateKilvishInput(event) {
1203
1236
 
1204
1237
 
1205
1238
 
1206
- if (inputField.type === 'password') {
1239
+ if (inputField.type === 'password') {
1240
+ hasValidationRule = true;
1207
1241
  // Always render UI directly *under* the field (or its .input-group)
1208
1242
  const { bars, label: strengthLabel, rulesUl } = ensurePassUI(inputField);
1209
1243
 
@@ -1328,8 +1362,9 @@ function validateKilvishInput(event) {
1328
1362
 
1329
1363
 
1330
1364
  // Files
1331
- if (inputField.type === 'file') {
1332
- const kilvishFileType = inputField.getAttribute('data-kilvish-file') || 'image';
1365
+ if (inputField.type === 'file') {
1366
+ hasValidationRule = true;
1367
+ const kilvishFileType = inputField.getAttribute('data-kilvish-file') || 'image';
1333
1368
  const [type, ...minMax] = kilvishFileType.split('_');
1334
1369
  const validTypes = validFilesTypes[kilvishFileType] || validFilesTypes[type] || validFilesTypes.image;
1335
1370
  const files = inputField.files;
@@ -1353,26 +1388,28 @@ function validateKilvishInput(event) {
1353
1388
  return false;
1354
1389
  }
1355
1390
  }
1356
- } else {
1357
- // Generic typing/commit validation
1358
- if (event.type === 'keyup') {
1359
- if (!validCharacters.test(inputField.value)) {
1360
- if (inputField.type !== 'password') addErrorMessage(inputField, 'Invalid character entered!');
1361
- inputField.style.border = '1px solid red';
1362
- }
1363
- }
1364
- if (event.type === 'change') {
1365
- if (!validCharacters.test(inputField.value)) {
1366
- inputField.value = '';
1367
- addErrorMessage(inputField, 'Invalid character or format!');
1368
- inputField.style.border = '1px solid red';
1369
- } else {
1370
- inputField.style.border = '';
1371
- clearFieldError(inputField); // class-agnostic clear on valid
1372
- }
1373
- }
1374
- }
1375
- }
1391
+ } else {
1392
+ // Generic typing/commit validation
1393
+ if (hasValidationRule) {
1394
+ if (event.type === 'keyup') {
1395
+ if (!validCharacters.test(inputField.value)) {
1396
+ if (inputField.type !== 'password') addErrorMessage(inputField, 'Invalid character entered!');
1397
+ inputField.style.border = '1px solid red';
1398
+ }
1399
+ }
1400
+ if (event.type === 'change') {
1401
+ if (!validCharacters.test(inputField.value)) {
1402
+ inputField.value = '';
1403
+ addErrorMessage(inputField, 'Invalid character or format!');
1404
+ inputField.style.border = '1px solid red';
1405
+ } else {
1406
+ inputField.style.border = '';
1407
+ clearFieldError(inputField); // class-agnostic clear on valid
1408
+ }
1409
+ }
1410
+ }
1411
+ }
1412
+ }
1376
1413
 
1377
1414
 
1378
1415
  function initPasswordStrengthMeter() {
@@ -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]*$/;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"]},s={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(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){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){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){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)n=/^[\d\-\s]{0,20}$/;else if("number"===a.type){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){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){n=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const t=a.value.trim(),r=new Date(t.replace(/[-\/]/g,"/")),l=new Date;l.setHours(0,0,0,0);const s=a.getAttribute("data-kilvish-date");if(s){const[t,n]=s.replace("_","").split("_").map(Number),i=new Date(l),o=new Date(l);if(i.setFullYear(l.getFullYear()-t),o.setFullYear(l.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<l)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){n=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=a.value.trim(),l="month"===a.type?new Date(r+"-01"):new Date(r.replace(/[-\/]/g,"/")),s=new Date;s.setHours(0,0,0,0);const i=a.getAttribute("data-kilvish-date");if(i)if(/^_(\d+)_(\d+)$/.test(i)){const[t,r]=i.replace("_","").split("_").map(Number),n=new Date(s),o=new Date(s);if(n.setFullYear(s.getFullYear()-t),o.setFullYear(s.getFullYear()-r),l>n||l<o)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(i)){const t=Number(i.replace("_","")),r=new Date(s);if(r.setFullYear(s.getFullYear()-t),l.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(i)){if("future"===i&&l<=s)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"===i&&l<s)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(i)){const t=Number(i.match(/(\d+)_days_future/)[1]),r=new Date(s);if(r.setDate(s.getDate()+t),l>r||l<s)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(i)){const t=Number(i.match(/^(\d+)_years_future$/)[1]),r=new Date(s);if(r.setFullYear(s.getFullYear()+t),l<s||l>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(i)){const t=Number(i.match(/^(\d+)_years_after$/)[1]),r=new Date(s);if(r.setFullYear(s.getFullYear()+t),l.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(i)){if("past"===i&&l>=s)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(i)){const t=Number(i.match(/^(\d+)_years_past$/)[1]),r=new Date(s);if(r.setFullYear(s.getFullYear()-t),l>s||l<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(i)){const t=Number(i.match(/^(\d+)_years_before$/)[1]),r=new Date(s);if(r.setFullYear(s.getFullYear()-t),l>=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(i)){const t=Number(i.match(/^(\d+)_years_after$/)[1]),r=new Date(s);if(r.setFullYear(s.getFullYear()+t),l<=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(i)){const[t,r]=i.match(/Between_(\d+)_(\d+)/).slice(1,3).map(Number),n=new Date(t,0,1),s=new Date(r,11,31);if(l<n||l>s)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(i)){const t=Number(i.match(/from_(\d+)/)[1]);if(l<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(i)){const t=Number(i.match(/till_(\d+)/)[1]);if(l>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"===i&&l.getTime()===s.getTime())return b(a,"Today's date is not allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("weekday"===i&&(0===l.getDay()||6===l.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"===i&&l.getDay()>=1&&l.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"===i&&1!==l.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(i)){const t=Number(i.match(/^exact_(\d+)$/)[1]),r=new Date(s);if(r.setFullYear(s.getFullYear()-t),l.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"===i){const t=new Date(l.getFullYear(),l.getMonth()+1,0).getDate();if(l.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 o=a.getAttribute("data-kilvish-dategroup");if(o&&/.+_[12]$/.test(o)){const[r,n]=o.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){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)n=/^[a-zA-Z0-9]{4,20}$/;else if("email"===a.type){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")){const t=a.value,r=a.getAttribute("data-kilvish-num");n=/^[0-9]*$/;let l=null,s=null;const i=r.match(/^_(\d+)_(\d+)$/);i&&(l=parseInt(i[1],10),s=parseInt(i[2],10));const o=r.match(/^exact_(\d+)$/),d=o?parseInt(o[1],10):null;/^\d*$/.test(t)?null!==d&&t.length!==d?(b(a,`This field must contain exactly ${d} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):l&&t.length<l||s&&t.length>s?(b(a,`This Field Must be between ${l} and ${s} 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")){const t=a.value,r=a.getAttribute("data-kilvish-num");n=/^[0-9]*$/;let l=null,s=null;const i=r?r.match(/^_(\d+)_(\d+)$/):null;i&&(l=parseInt(i[1],10),s=parseInt(i[2],10)),"exact_20"===r&&(n=/^[0-9]{20}$/),n.test(t)?l&&t.length<l||s&&t.length>s?(b(a,`This Field Must be between ${l} and ${s} 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")){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")){const r=a.getAttribute("data-kilvish-amount");n=/^\d+(\.\d{0,2})?$/;let l="USD",s=null,i=null;const o=r.match(/^([A-Z]{3})(?:_(\d+)_(\d+))?$/);o&&(l=o[1],s=o[2]?parseFloat(o[2]):null,i=o[3]?parseFloat(o[3]):null);const d=()=>{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 s=r.indexOf(".");-1!==s&&e>s&&(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=`${l} ${r||"0.00"} .`},c=()=>{if(a.readOnly)return;let e=parseFloat(a.value||"0").toFixed(2),t=a.nextElementSibling;return null!==s&&e<s?(b(a,`Amount must be at least ${s.toFixed(2)} ${l}.`),a.style.border="2px solid red",a.value="",void(t&&(t.textContent=""))):null!==i&&e>i?(b(a,`Amount must not exceed ${i.toFixed(2)} ${l}.`),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",d),a.addEventListener("blur",c),a.dataset.kilAmountBound="1"),"keyup"!==e.type&&"change"!==e.type||d()}if("password"===a.type){const{bars:r,label:l,rulesUl:s}=v(a),i=a.getAttribute("data-kilvish-password")||"12",[o,d]=i.split("_"),c=parseInt(o,10)||12,u=parseInt(d||"128",10);n=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 a=s.querySelector(`li[data-rule="${e}"]`);a||(a=t.createElement("li"),a.setAttribute("data-rule",e),a.textContent=`❌ ${p[e]}`,a.style.color="red",a.style.fontSize="12px",s.appendChild(a)),m[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>=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),y(e)&&(t-=2),Math.max(0,t)},h=a.value||"",g={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:!y(h)};Object.keys(g).forEach((e=>{const t=g[e];m[e].textContent=`${t?"✅":"❌"} ${p[e]}`,m[e].style.color=t?"green":"red"}));const b=f(h);r.forEach((e=>e.style.background="lightgray")),b<=2?(r[0]&&(r[0].style.background="red"),l.textContent="Weak",l.style.color="red"):b<=4?(r[0]&&(r[0].style.background="yellow"),r[1]&&(r[1].style.background="yellow"),l.textContent="Medium",l.style.color="orange"):(r[0]&&(r[0].style.background="green"),r[1]&&(r[1].style.background="green"),r[2]&&(r[2].style.background="green"),l.textContent="Strong",l.style.color="green");const x=n.test(h)&&Object.values(g).every(Boolean);return a.style.border=x?"1px solid green":"1px solid red",void(x||"change"!==e.type||(a.value=""))}if("file"===a.type){const e=a.getAttribute("data-kilvish-file")||"image",[t,...r]=e.split("_"),n=l[e]||l[t]||l.image,i=a.files;let o=1,d=1/0;if(r.length>=2&&(o=parseInt(r[0],10),d=parseInt(r[1],10)),i.length<o||i.length>d)return b(a,`Please select between ${o} and ${d} valid file(s).`),a.value="",a.style.border="1px solid red",!1;const c=s[e]||t.toUpperCase();for(const e of i)if(!n.includes(e.type))return b(a,`Invalid file type. Allowed types: ${c}.`),a.value="",a.style.border="1px solid red",!1}else"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]*$/;const n={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"]},s={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(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){a=/^[a-zA-Z\s-]*$/;const r=/^[a-zA-Z0-9._@-\s]+$/,n=t.value;if(r.test(n)&&(n.length>20||n.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){a=/^\d{6}$/;const r=/^\d+$/,n=t.value;if(r.test(n)&&6!==n.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){a=/^\d{0,6}(\.\d{0,2})?$/;const r=/^\d+$/,n=t.value;if(r.test(n)&&n.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)a=/^[\d\-\s]{0,20}$/;else if("number"===t.type){a=/^\d{0,20}$/;const r=/^\d+$/,n=t.value;if(r.test(n)&&(n.length>20||n.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){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){a=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=t.value.trim(),n=new Date(r.replace(/[-\/]/g,"/")),s=new Date;s.setHours(0,0,0,0);const o=t.getAttribute("data-kilvish-date");if(o){const[r,a]=o.replace("_","").split("_").map(Number),l=new Date(s),i=new Date(s);if(l.setFullYear(s.getFullYear()-r),i.setFullYear(s.getFullYear()-a),n>l||n<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(n<s)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){a=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=t.value.trim(),n="month"===t.type?new Date(r+"-01"):new Date(r.replace(/[-\/]/g,"/")),s=new Date;s.setHours(0,0,0,0);const o=t.getAttribute("data-kilvish-date");if(o)if(/^_(\d+)_(\d+)$/.test(o)){const[r,a]=o.replace("_","").split("_").map(Number),l=new Date(s),i=new Date(s);if(l.setFullYear(s.getFullYear()-r),i.setFullYear(s.getFullYear()-a),n>l||n<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(o)){const r=Number(o.replace("_","")),a=new Date(s);if(a.setFullYear(s.getFullYear()-r),n.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(o)){if("future"===o&&n<=s)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"===o&&n<s)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(o)){const r=Number(o.match(/(\d+)_days_future/)[1]),a=new Date(s);if(a.setDate(s.getDate()+r),n>a||n<s)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(o)){const r=Number(o.match(/^(\d+)_years_future$/)[1]),a=new Date(s);if(a.setFullYear(s.getFullYear()+r),n<s||n>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(o)){const r=Number(o.match(/^(\d+)_years_after$/)[1]),a=new Date(s);if(a.setFullYear(s.getFullYear()+r),n.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(o)){if("past"===o&&n>=s)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(o)){const r=Number(o.match(/^(\d+)_years_past$/)[1]),a=new Date(s);if(a.setFullYear(s.getFullYear()-r),n>s||n<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(o)){const r=Number(o.match(/^(\d+)_years_before$/)[1]),a=new Date(s);if(a.setFullYear(s.getFullYear()-r),n>=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(o)){const r=Number(o.match(/^(\d+)_years_after$/)[1]),a=new Date(s);if(a.setFullYear(s.getFullYear()+r),n<=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(o)){const[r,a]=o.match(/Between_(\d+)_(\d+)/).slice(1,3).map(Number),s=new Date(r,0,1),l=new Date(a,11,31);if(n<s||n>l)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(o)){const r=Number(o.match(/from_(\d+)/)[1]);if(n<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(o)){const r=Number(o.match(/till_(\d+)/)[1]);if(n>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"===o&&n.getTime()===s.getTime())return addErrorMessage(t,"Today's date is not allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("weekday"===o&&(0===n.getDay()||6===n.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"===o&&n.getDay()>=1&&n.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"===o&&1!==n.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(o)){const r=Number(o.match(/^exact_(\d+)$/)[1]),a=new Date(s);if(a.setFullYear(s.getFullYear()-r),n.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"===o){const r=new Date(n.getFullYear(),n.getMonth()+1,0).getDate();if(n.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 l=t.getAttribute("data-kilvish-dategroup");if(l&&/.+_[12]$/.test(l)){const[r,a]=l.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){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 n=t.getAttribute("data-kilvish-age")||"18";if(/^(\d+)$/.test(n)){const r=Number(n);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(n)){const[r,s]=n.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>s)return addErrorMessage(t,`Age cannot exceed ${s} 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)a=/^[a-zA-Z0-9]{4,20}$/;else if("email"===t.type){a=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;const r=/^[a-zA-Z0-9._@-]+$/,n=t.value;if(r.test(n)&&!a.test(n))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")){const r=t.value,n=t.getAttribute("data-kilvish-num");a=/^[0-9]*$/;let s=null,o=null;const l=n.match(/^_(\d+)_(\d+)$/);l&&(s=parseInt(l[1],10),o=parseInt(l[2],10));const i=n.match(/^exact_(\d+)$/),d=i?parseInt(i[1],10):null;/^\d*$/.test(r)?null!==d&&r.length!==d?(addErrorMessage(t,`This field must contain exactly ${d} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):s&&r.length<s||o&&r.length>o?(addErrorMessage(t,`This Field Must be between ${s} and ${o} 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")){const r=t.value,n=t.getAttribute("data-kilvish-num");a=/^[0-9]*$/;let s=null,o=null;const l=n?n.match(/^_(\d+)_(\d+)$/):null;l&&(s=parseInt(l[1],10),o=parseInt(l[2],10)),"exact_20"===n&&(a=/^[0-9]{20}$/),a.test(r)?s&&r.length<s||o&&r.length>o?(addErrorMessage(t,`This Field Must be between ${s} and ${o} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):t.style.border="":(addErrorMessage(t,"exact_20"===n?"This field must contain exactly 20 digits.":"Only numerical characters are allowed."),t.style.border="2px solid red")}if(t.hasAttribute("data-kilvish-char")){const r=t.value,n=t.getAttribute("data-kilvish-char");if(n.startsWith("Yes")||n.startsWith("mix")){"mix"===n?a=/^[a-zA-Z0-9]*$/:"Yes"===n&&(a=/^[a-zA-Z]*$/);const s=n.split("_").slice(1).join("");if(s&&(a=new RegExp(`^[a-zA-Z0-9${s}]*$`)),!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")){const r=t.getAttribute("data-kilvish-amount");a=/^\d+(\.\d{0,2})?$/;let n="USD",s=null,o=null;const l=r.match(/^([A-Z]{3})(?:_(\d+)_(\d+))?$/);l&&(n=l[1],s=l[2]?parseFloat(l[2]):null,o=l[3]?parseFloat(l[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 s=r.indexOf(".");-1!==s&&e>s&&(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=`${n} ${r||"0.00"} .`})),t.addEventListener("blur",(()=>{if(t.readOnly)return;let r=parseFloat(t.value||"0").toFixed(2),a=t.nextElementSibling;return null!==s&&r<s?(addErrorMessage(t,`Amount must be at least ${s.toFixed(2)} ${n}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value="",a&&(a.textContent="")))):null!==o&&r>o?(addErrorMessage(t,`Amount must not exceed ${o.toFixed(2)} ${n}.`),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){const{bars:r,label:n,rulesUl:s}=ensurePassUI(t),o=t.getAttribute("data-kilvish-password")||"12",[l,i]=o.split("_"),d=parseInt(l,10)||12,c=parseInt(i||"128",10);a=new RegExp(`^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[\\W_]).{${d},${c}}$`);const u={length:`Password must be between ${d} and ${c} 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)"},p={};Object.keys(u).forEach((e=>{let t=s.querySelector(`li[data-rule="${e}"]`);t||(t=document.createElement("li"),t.setAttribute("data-rule",e),t.textContent=`❌ ${u[e]}`,t.style.color="red",t.style.fontSize="12px",s.appendChild(t)),p[e]=t}));const m=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},g=e=>{let t=0;return e.length>=d&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),m(e)&&(t-=2),Math.max(0,t)},y=t.value||"",f={length:y.length>=d&&y.length<=c,uppercase:/[A-Z]/.test(y),lowercase:/[a-z]/.test(y),number:/\d/.test(y),special:/[\W_]/.test(y),sequential:!m(y)};Object.keys(f).forEach((e=>{const t=f[e];p[e].textContent=`${t?"✅":"❌"} ${u[e]}`,p[e].style.color=t?"green":"red"}));const h=g(y);r.forEach((e=>e.style.background="lightgray")),h<=2?(r[0]&&(r[0].style.background="red"),n.textContent="Weak",n.style.color="red"):h<=4?(r[0]&&(r[0].style.background="yellow"),r[1]&&(r[1].style.background="yellow"),n.textContent="Medium",n.style.color="orange"):(r[0]&&(r[0].style.background="green"),r[1]&&(r[1].style.background="green"),r[2]&&(r[2].style.background="green"),n.textContent="Strong",n.style.color="green");const b=a.test(y)&&Object.values(f).every(Boolean);return t.style.border=b?"1px solid green":"1px solid red",void(b||"change"!==e.type||(t.value=""))}if("file"===t.type){const e=t.getAttribute("data-kilvish-file")||"image",[r,...a]=e.split("_"),o=n[e]||n[r]||n.image,l=t.files;let i=1,d=1/0;if(a.length>=2&&(i=parseInt(a[0],10),d=parseInt(a[1],10)),l.length<i||l.length>d)return addErrorMessage(t,`Please select between ${i} and ${d} valid file(s).`),t.value="",t.style.border="1px solid red",!1;const c=s[e]||r.toUpperCase();for(const e of l)if(!o.includes(e.type))return addErrorMessage(t,`Invalid file type. Allowed types: ${c}.`),t.value="",t.style.border="1px solid red",!1}else"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});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kilvalidate",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "main": "kilnextvalidation.js",
5
5
  "browser": "kilnextvalidation.min.js",
6
6
  "files": [