kilvalidate 3.0.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kilnextvalidation.js +76 -55
- package/kilnextvalidation.min.js +1 -1
- package/kilvish.min.js +1 -1
- package/package.json +1 -1
package/kilnextvalidation.js
CHANGED
|
@@ -697,8 +697,9 @@ 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
|
+
let hasValidationRule = false;
|
|
702
703
|
|
|
703
704
|
// Define allowed image/file types
|
|
704
705
|
const validFilesTypes = {
|
|
@@ -723,8 +724,9 @@ function validateKilvishInput(event) {
|
|
|
723
724
|
clearFieldError(inputField);
|
|
724
725
|
|
|
725
726
|
// --- Custom validations by field/name/type
|
|
726
|
-
if (inputField.name === 'description' || inputField.name === 'address') {
|
|
727
|
-
|
|
727
|
+
if (inputField.name === 'description' || inputField.name === 'address') {
|
|
728
|
+
hasValidationRule = true;
|
|
729
|
+
validCharacters = /^[a-zA-Z0-9@,._\s-'"*]*$/;
|
|
728
730
|
if (inputField.value.length > 400) {
|
|
729
731
|
addErrorMessage(inputField, 'Input exceeds the maximum length of 400 characters!');
|
|
730
732
|
inputField.style.border = '1px solid red';
|
|
@@ -732,8 +734,9 @@ function validateKilvishInput(event) {
|
|
|
732
734
|
return;
|
|
733
735
|
}
|
|
734
736
|
|
|
735
|
-
} else if (inputField.name === 'firstname' || inputField.name === 'lastname' || inputField.name === 'appointment_by') {
|
|
736
|
-
|
|
737
|
+
} else if (inputField.name === 'firstname' || inputField.name === 'lastname' || inputField.name === 'appointment_by') {
|
|
738
|
+
hasValidationRule = true;
|
|
739
|
+
validCharacters = /^[a-zA-Z\s-]*$/; // allow hyphen
|
|
737
740
|
const allowedChars = /^[a-zA-Z0-9._@-\s]+$/;
|
|
738
741
|
const inputValue = inputField.value;
|
|
739
742
|
if (allowedChars.test(inputValue)) {
|
|
@@ -746,8 +749,9 @@ function validateKilvishInput(event) {
|
|
|
746
749
|
}
|
|
747
750
|
inputField.style.border = '';
|
|
748
751
|
|
|
749
|
-
} else if (inputField.name === 'otp') {
|
|
750
|
-
|
|
752
|
+
} else if (inputField.name === 'otp') {
|
|
753
|
+
hasValidationRule = true;
|
|
754
|
+
validCharacters = /^\d{6}$/;
|
|
751
755
|
const numericOnlyPattern = /^\d+$/;
|
|
752
756
|
const inputValue = inputField.value;
|
|
753
757
|
if (numericOnlyPattern.test(inputValue) && inputValue.length !== 6) {
|
|
@@ -758,8 +762,9 @@ function validateKilvishInput(event) {
|
|
|
758
762
|
}
|
|
759
763
|
inputField.style.border = '';
|
|
760
764
|
|
|
761
|
-
} else if (inputField.name === 'number_of_items') {
|
|
762
|
-
|
|
765
|
+
} else if (inputField.name === 'number_of_items') {
|
|
766
|
+
hasValidationRule = true;
|
|
767
|
+
validCharacters = /^\d{0,6}(\.\d{0,2})?$/;
|
|
763
768
|
const numericOnlyPattern = /^\d+$/;
|
|
764
769
|
const inputValue = inputField.value;
|
|
765
770
|
if (numericOnlyPattern.test(inputValue) && inputValue.length > 3) {
|
|
@@ -770,11 +775,13 @@ function validateKilvishInput(event) {
|
|
|
770
775
|
}
|
|
771
776
|
inputField.style.border = '';
|
|
772
777
|
|
|
773
|
-
} else if (inputField.name === 'contact' || inputField.id === 'agent_contact' || inputField.name === 'fullcontact' ) {
|
|
774
|
-
|
|
778
|
+
} else if (inputField.name === 'contact' || inputField.id === 'agent_contact' || inputField.name === 'fullcontact' ) {
|
|
779
|
+
hasValidationRule = true;
|
|
780
|
+
validCharacters = /^[\d\-\s]{0,20}$/;
|
|
775
781
|
|
|
776
|
-
} else if (inputField.type === 'number') {
|
|
777
|
-
|
|
782
|
+
} else if (inputField.type === 'number') {
|
|
783
|
+
hasValidationRule = true;
|
|
784
|
+
validCharacters = /^\d{0,20}$/;
|
|
778
785
|
const numericOnlyPattern = /^\d+$/;
|
|
779
786
|
const inputValue = inputField.value;
|
|
780
787
|
if (numericOnlyPattern.test(inputValue) && (inputValue.length > 20 || inputValue.length < 1)) {
|
|
@@ -785,8 +792,9 @@ function validateKilvishInput(event) {
|
|
|
785
792
|
}
|
|
786
793
|
inputField.style.border = '';
|
|
787
794
|
|
|
788
|
-
} else if (inputField.type === 'tel') {
|
|
789
|
-
|
|
795
|
+
} else if (inputField.type === 'tel') {
|
|
796
|
+
hasValidationRule = true;
|
|
797
|
+
let inputValue = inputField.value.trim().replace(/\s+/g, '');
|
|
790
798
|
inputField.value = inputValue;
|
|
791
799
|
const phonePattern = /^\+?\d{7,15}$/;
|
|
792
800
|
validCharacters = /^\+?\d{7,15}$/;
|
|
@@ -798,8 +806,9 @@ function validateKilvishInput(event) {
|
|
|
798
806
|
}
|
|
799
807
|
inputField.style.border = '';
|
|
800
808
|
|
|
801
|
-
} else if (inputField.name === 'kildate') {
|
|
802
|
-
|
|
809
|
+
} else if (inputField.name === 'kildate') {
|
|
810
|
+
hasValidationRule = true;
|
|
811
|
+
validCharacters = /^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;
|
|
803
812
|
const inputValue = inputField.value.trim();
|
|
804
813
|
const inputDate = new Date(inputValue.replace(/[-\/]/g, '/'));
|
|
805
814
|
const today = new Date(); today.setHours(0,0,0,0);
|
|
@@ -825,8 +834,9 @@ function validateKilvishInput(event) {
|
|
|
825
834
|
}
|
|
826
835
|
inputField.style.border = '';
|
|
827
836
|
|
|
828
|
-
} else if (inputField.type === 'date' || inputField.type === 'month') {
|
|
829
|
-
|
|
837
|
+
} else if (inputField.type === 'date' || inputField.type === 'month') {
|
|
838
|
+
hasValidationRule = true;
|
|
839
|
+
validCharacters = /^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;
|
|
830
840
|
const inputValue = inputField.value.trim();
|
|
831
841
|
const inputDate = (inputField.type === 'month')
|
|
832
842
|
? new Date(inputValue + '-01')
|
|
@@ -1020,8 +1030,9 @@ function validateKilvishInput(event) {
|
|
|
1020
1030
|
inputField.style.border = '';
|
|
1021
1031
|
return;
|
|
1022
1032
|
|
|
1023
|
-
} else if (inputField.name === 'age') {
|
|
1024
|
-
|
|
1033
|
+
} else if (inputField.name === 'age') {
|
|
1034
|
+
hasValidationRule = true;
|
|
1035
|
+
const inputValue = inputField.value.trim();
|
|
1025
1036
|
const ageValue = parseInt(inputValue, 10);
|
|
1026
1037
|
if (isNaN(ageValue)) {
|
|
1027
1038
|
addErrorMessage(inputField, 'Please enter a valid number for age.');
|
|
@@ -1057,10 +1068,12 @@ function validateKilvishInput(event) {
|
|
|
1057
1068
|
}
|
|
1058
1069
|
|
|
1059
1070
|
// model_name / models[]
|
|
1060
|
-
if (inputField.name === 'model_name' || inputField.name === 'models[]') {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1071
|
+
if (inputField.name === 'model_name' || inputField.name === 'models[]') {
|
|
1072
|
+
hasValidationRule = true;
|
|
1073
|
+
validCharacters = /^[a-zA-Z0-9]{4,20}$/;
|
|
1074
|
+
} else if (inputField.type === 'email') {
|
|
1075
|
+
hasValidationRule = true;
|
|
1076
|
+
validCharacters = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
|
|
1064
1077
|
const allowedEmailChars = /^[a-zA-Z0-9._@-]+$/;
|
|
1065
1078
|
const inputValue = inputField.value;
|
|
1066
1079
|
if (allowedEmailChars.test(inputValue) && !validCharacters.test(inputValue)) {
|
|
@@ -1073,8 +1086,9 @@ function validateKilvishInput(event) {
|
|
|
1073
1086
|
}
|
|
1074
1087
|
|
|
1075
1088
|
// data-kilvish-num
|
|
1076
|
-
if (inputField.hasAttribute('data-kilvish-num')) {
|
|
1077
|
-
|
|
1089
|
+
if (inputField.hasAttribute('data-kilvish-num')) {
|
|
1090
|
+
hasValidationRule = true;
|
|
1091
|
+
const inputValue = inputField.value;
|
|
1078
1092
|
const kilvishType = inputField.getAttribute('data-kilvish-num');
|
|
1079
1093
|
validCharacters = /^[0-9]*$/;
|
|
1080
1094
|
let min = null, max = null;
|
|
@@ -1100,8 +1114,9 @@ function validateKilvishInput(event) {
|
|
|
1100
1114
|
}
|
|
1101
1115
|
|
|
1102
1116
|
// data-kilvish-num11
|
|
1103
|
-
if (inputField.hasAttribute('data-kilvish-num11')) {
|
|
1104
|
-
|
|
1117
|
+
if (inputField.hasAttribute('data-kilvish-num11')) {
|
|
1118
|
+
hasValidationRule = true;
|
|
1119
|
+
const inputValue = inputField.value;
|
|
1105
1120
|
const kilvishType = inputField.getAttribute('data-kilvish-num');
|
|
1106
1121
|
validCharacters = /^[0-9]*$/;
|
|
1107
1122
|
let min = null, max = null;
|
|
@@ -1122,8 +1137,9 @@ function validateKilvishInput(event) {
|
|
|
1122
1137
|
}
|
|
1123
1138
|
|
|
1124
1139
|
// data-kilvish-char
|
|
1125
|
-
if (inputField.hasAttribute('data-kilvish-char')) {
|
|
1126
|
-
|
|
1140
|
+
if (inputField.hasAttribute('data-kilvish-char')) {
|
|
1141
|
+
hasValidationRule = true;
|
|
1142
|
+
const inputValue = inputField.value;
|
|
1127
1143
|
const charType = inputField.getAttribute('data-kilvish-char');
|
|
1128
1144
|
if (charType.startsWith('Yes') || charType.startsWith('mix')) {
|
|
1129
1145
|
if (charType === 'mix') validCharacters = /^[a-zA-Z0-9]*$/;
|
|
@@ -1141,6 +1157,7 @@ function validateKilvishInput(event) {
|
|
|
1141
1157
|
|
|
1142
1158
|
// data-kilvish-amount
|
|
1143
1159
|
if (inputField.hasAttribute('data-kilvish-amount')) {
|
|
1160
|
+
hasValidationRule = true;
|
|
1144
1161
|
const kilvishType = inputField.getAttribute('data-kilvish-amount');
|
|
1145
1162
|
validCharacters = /^\d+(\.\d{0,2})?$/;
|
|
1146
1163
|
let currency = 'USD', minAmount = null, maxAmount = null;
|
|
@@ -1203,7 +1220,8 @@ function validateKilvishInput(event) {
|
|
|
1203
1220
|
|
|
1204
1221
|
|
|
1205
1222
|
|
|
1206
|
-
if (inputField.type === 'password') {
|
|
1223
|
+
if (inputField.type === 'password') {
|
|
1224
|
+
hasValidationRule = true;
|
|
1207
1225
|
// Always render UI directly *under* the field (or its .input-group)
|
|
1208
1226
|
const { bars, label: strengthLabel, rulesUl } = ensurePassUI(inputField);
|
|
1209
1227
|
|
|
@@ -1328,8 +1346,9 @@ function validateKilvishInput(event) {
|
|
|
1328
1346
|
|
|
1329
1347
|
|
|
1330
1348
|
// Files
|
|
1331
|
-
if (inputField.type === 'file') {
|
|
1332
|
-
|
|
1349
|
+
if (inputField.type === 'file') {
|
|
1350
|
+
hasValidationRule = true;
|
|
1351
|
+
const kilvishFileType = inputField.getAttribute('data-kilvish-file') || 'image';
|
|
1333
1352
|
const [type, ...minMax] = kilvishFileType.split('_');
|
|
1334
1353
|
const validTypes = validFilesTypes[kilvishFileType] || validFilesTypes[type] || validFilesTypes.image;
|
|
1335
1354
|
const files = inputField.files;
|
|
@@ -1353,26 +1372,28 @@ function validateKilvishInput(event) {
|
|
|
1353
1372
|
return false;
|
|
1354
1373
|
}
|
|
1355
1374
|
}
|
|
1356
|
-
} else {
|
|
1357
|
-
// Generic typing/commit validation
|
|
1358
|
-
if (
|
|
1359
|
-
if (
|
|
1360
|
-
if (inputField.
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
if (
|
|
1366
|
-
inputField.value
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
}
|
|
1375
|
+
} else {
|
|
1376
|
+
// Generic typing/commit validation
|
|
1377
|
+
if (hasValidationRule) {
|
|
1378
|
+
if (event.type === 'keyup') {
|
|
1379
|
+
if (!validCharacters.test(inputField.value)) {
|
|
1380
|
+
if (inputField.type !== 'password') addErrorMessage(inputField, 'Invalid character entered!');
|
|
1381
|
+
inputField.style.border = '1px solid red';
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
if (event.type === 'change') {
|
|
1385
|
+
if (!validCharacters.test(inputField.value)) {
|
|
1386
|
+
inputField.value = '';
|
|
1387
|
+
addErrorMessage(inputField, 'Invalid character or format!');
|
|
1388
|
+
inputField.style.border = '1px solid red';
|
|
1389
|
+
} else {
|
|
1390
|
+
inputField.style.border = '';
|
|
1391
|
+
clearFieldError(inputField); // class-agnostic clear on valid
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1376
1397
|
|
|
1377
1398
|
|
|
1378
1399
|
function initPasswordStrengthMeter() {
|
package/kilnextvalidation.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! kilvalidate | Author: Kilvish (Vasu Birla) | MIT */
|
|
2
|
-
!function(e,t){"object"==typeof module&&module.exports?module.exports=t(e):"function"==typeof define&&define.amd?define((function(){return t(e)})):e&&(e.kilvalidate=t(e))}("undefined"!=typeof window?window:"undefined"!=typeof globalThis?globalThis:void 0,(function(e){if(!e||!e.document){const e=()=>{},t=()=>!1;return{validateRequiredFields:t,addRealTimeValidation:e,validateForm:t,addAsteriskToRequiredFields:e,attachInputEvents:e,addValidateFormToSubmitButtons:e,validateKilvishInput:e,addErrorMessage:e,init:e,initPasswordStrengthMeter:e}}const t=e.document;!function(){if(t.getElementById("kil-error-style"))return;const e=t.createElement("style");e.id="kil-error-style",e.textContent="\n .error-message {\n display:block;\n min-height:16px; /* reserves space even when empty */\n margin-top:4px;\n font-size:12px;\n color:#d32f2f;\n line-height:1.25;\n opacity:1;\n transition: opacity .12s ease;\n }\n .error-message.is-hidden{ opacity:0; }\n ",t.head.appendChild(e)}();const a=t=>e.CSS&&"function"==typeof e.CSS.escape?e.CSS.escape(String(t)):String(t).replace(/["\\]/g,"\\$&");function r(e){if(!e)return null;if(e.tagName&&"FORM"===String(e.tagName).toUpperCase())return e;if("string"==typeof e){return/^[#.\[]/.test(e)||e.includes(" ")||e.includes("[")?t.querySelector(e):t.getElementById(e)||t.querySelector(e)}return e.querySelector?e:null}function n(e){if(!e)return null;const r=e.form||t;let n=null;if(e.id&&(n=r.querySelector(`label[for="${a(e.id)}"]`)),!n&&e.name&&(n=r.querySelector(`label[for="${a(e.name)}"]`)),n||(n=e.closest("label")),!n){const t=e.closest("fieldset");t&&(n=t.querySelector("legend"))}return n}function l(e){const a=n(e);if(!a)return;let r=a.querySelector(".kil-required-star");r||(r=t.createElement("span"),r.className="kil-required-star",r.textContent=" *",a.appendChild(r)),r.style.visibility="visible"}function s(e){const t=n(e);if(!t)return;const a=t.querySelector(".kil-required-star");a&&(a.style.visibility="hidden")}function i(e){const t=r(e);if(!t)return console.warn("Form not found for validation:",e),!1;const a=t.querySelectorAll("input[required], select[required], textarea[required]"),n=(t.querySelectorAll("fieldset.radios"),t.querySelectorAll('input[type="radio"]')),l={},s=new Set;t.querySelectorAll('input[type="checkbox"]').forEach((e=>{const t=e.name;l[t]||(l[t]=[]),l[t].push(e),e.hasAttribute("required")&&s.add(t)}));t.querySelectorAll(".select2");let i=!0,o="This Field is Required.";if(t.querySelectorAll(".error-message").forEach((e=>{e.textContent="",e.classList.add("is-hidden")})),a.forEach((e=>{e.style.border=""})),a.forEach((e=>{const t=e.closest(".form-group")||e.parentNode;e.parentNode;if("date"==e.type){o="Please Select Date",e.style.border="";e.value.trim()||(i=!1,e.style.border="1px solid red",b(t,o))}else o="comments"==e.name?"Please Enter Comments":"email"==e.type?"Please Enter Email":"password"==e.type?"Please Enter Password":"This Field is Required.";const a=e.getAttribute("data-kilvish-name");let r;if(o=`${a||"This"} Field is Required.`,("tel"===e.type||e.hasAttribute("data-kilvish-tel"))&&(r=function(e){const t=e.closest(".kiltel-phone-wrap")||e.parentElement,a=t&&(t.querySelector('input[name="contact"]')||t.querySelector("#contact"));if(a)return(a.value||"").replace(/\D/g,"").length<7;const r=(e.value||"").trim().replace(/\s|-/g,"");return!r||(!!/^\+?$/.test(r)||(!!/^\+?\d{1,4}$/.test(r)||r.replace(/\D/g,"").length<7))}(e),r&&(o=`${a||"Phone"} is required (enter full number, not just country code).`)),r)return i=!1,e.style.border="1px solid red",void b(e,o);e.value.trim()||(i=!1,e.style.border="1px solid red",b(t,o))})),n.length>0){const e={};n.forEach((t=>{const a=t.name;e[a]||(e[a]={isSelected:!1,groupElement:t.closest(".form-group")||t.closest(".mb-3")||t.closest(".form-check")||t.closest(".radios")||t.closest(".col-md-6")}),t.checked&&(e[a].isSelected=!0)})),Object.entries(e).forEach((([e,t])=>{if(!t.isSelected){i=!1;const a="Please select one option.";if(!t.groupElement)return void console.error("Invalid group element for radio group:",e);b(t.groupElement,a)}}))}return Object.keys(l).forEach((e=>{const t=l[e];if(t.some((e=>e.hasAttribute("data-ignore-kilvish"))))return;if(!t.some((e=>e.checked))){i=!1;const a=s.has(e)?"Please check this box to proceed":"Please select at least one option.";b(t[0].closest(".form-group")||t[0].closest(".form-check")||t[0].closest(".checkbox-container")||t[0].closest(".some-other-container"),a)}})),i}function o(e){const t=r(e);if(!t)return;const a=t.querySelectorAll("input[required], select[required], textarea[required]"),n=(e,t=!0)=>{t?l(e):s(e)};function i(e){const t=e.form||e.closest("form");if(!t)return;const a=e.nextElementSibling;let r=e,n="afterend",l=e.name||e.id||"field";"SELECT"===e.tagName&&a&&(a.classList.contains("select2")||a.classList.contains("select2-container"))?(r=a,n="afterend",l=e.name||e.id||"select"):e.parentElement&&e.parentElement.classList.contains("input-group")&&(r=e.parentElement,n="afterend",l=e.name||e.id||"inputgroup");const i=t.querySelector(`#kil_err_${String(l).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);i&&(i.textContent="",i.classList.add("is-hidden")),e.style.border="",s(e)}a.forEach((e=>{if("1"===e.dataset.kilRealtimeBound)return;const t=()=>{e.value.trim()?(i(e),n(e,!1)):n(e,!0)};e.addEventListener("input",t),e.addEventListener("change",t),e.dataset.kilRealtimeBound="1"}));const o=t.querySelectorAll('input[type="radio"]');[...new Set(Array.from(o).map((e=>e.name)))].forEach((e=>{const a=t.querySelectorAll(`input[type="radio"][name="${e}"]`);a.forEach((e=>{"1"!==e.dataset.kilRadioBound&&(e.addEventListener("change",(()=>{Array.from(a).some((e=>e.checked))&&i(e)})),e.dataset.kilRadioBound="1")}))}));const d=t.querySelectorAll('input[type="checkbox"]');[...new Set(Array.from(d).map((e=>e.name)))].forEach((e=>{const a=t.querySelectorAll(`input[type="checkbox"][name="${e}"]`);a.forEach((e=>{"1"!==e.dataset.kilCheckboxBound&&(e.addEventListener("change",(()=>{Array.from(a).some((e=>e.checked))&&i(e)})),e.dataset.kilCheckboxBound="1")}))}))}function d(t,a){const r=i(t);if(!r){const t=a||e.event;t&&t.preventDefault&&t.preventDefault()}return r}function c(e=t){e.querySelectorAll("label, legend").forEach((e=>{e.querySelectorAll("span").forEach((e=>{e.classList.contains("kil-required-star")||"*"!==e.textContent.trim()||e.remove()}));const t=e.querySelectorAll(".kil-required-star");for(let e=1;e<t.length;e++)t[e].remove()}))}function u(){t.querySelectorAll("input[required], select[required], textarea[required]").forEach(l)}function p(){t.querySelectorAll("input, select, textarea").forEach((e=>{"1"!==e.dataset.kilInputBound&&(e.hasAttribute("data-ignore-kilvish")||(e.addEventListener("keyup",h),e.addEventListener("change",h),e.dataset.kilInputBound="1"))}))}function m(){t.querySelectorAll("form").forEach((e=>{const t=e.id;"1"!==e.dataset.kilFormSubmitBound&&(e.addEventListener("submit",(t=>d(e,t))),e.dataset.kilFormSubmitBound="1");const a=t?`#${t}`:e;e.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((e=>{"1"!==e.dataset.kilSubmitBound&&(e.addEventListener("click",(e=>d(a,e))),e.dataset.kilSubmitBound="1")}))}))}!function(){if(t.getElementById("kil-req-style"))return;const e=t.createElement("style");e.id="kil-req-style",e.textContent="\n .kil-required-star{ color:#d32f2f; margin-left:2px; }\n .error-message{ display:block; min-height:16px; margin-top:4px; font-size:12px; color:#d32f2f; line-height:1.25; opacity:1; transition:opacity .12s ease; }\n .error-message.is-hidden{ opacity:0; }\n ",t.head.appendChild(e)}();let y=null;function f(){c(),u();t.querySelectorAll("form").forEach((e=>{const t=e.id;o(t||e)})),p(),m(),g(),t.querySelectorAll('input[type="password"]').forEach(x),!y&&e.MutationObserver&&(y=new MutationObserver((e=>{for(const t of e)t.addedNodes&&t.addedNodes.forEach((e=>{e instanceof HTMLElement&&(e.matches&&e.matches('input[type="password"]')&&x(e),e.querySelectorAll&&e.querySelectorAll('input[type="password"]').forEach(x))}))})),y.observe(t.documentElement,{childList:!0,subtree:!0}))}function h(e){const a=e.target;if(a.hasAttribute("data-ignore-kilvish"))return;function r(e){const t=e.form||e.closest("form");if(!t)return;const a=e.nextElementSibling;let r=e.name||e.id||"field";"SELECT"===e.tagName&&a&&(a.classList.contains("select2")||a.classList.contains("select2-container"))?r=e.name||e.id||"select":e.parentElement&&e.parentElement.classList.contains("input-group")&&(r=e.name||e.id||"inputgroup");const n=t.querySelector(`#kil_err_${String(r).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);n&&(n.textContent="",n.classList.add("is-hidden")),e.style.border=""}let n=/^[a-zA-Z\s]*$/;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 l(e){const a=n(e);if(!a)return;let r=a.querySelector(".kil-required-star");r||(r=t.createElement("span"),r.className="kil-required-star",r.textContent=" *",a.appendChild(r)),r.style.visibility="visible"}function s(e){const t=n(e);if(!t)return;const a=t.querySelector(".kil-required-star");a&&(a.style.visibility="hidden")}function i(e){const t=r(e);if(!t)return console.warn("Form not found for validation:",e),!1;const a=t.querySelectorAll("input[required], select[required], textarea[required]"),n=(t.querySelectorAll("fieldset.radios"),t.querySelectorAll('input[type="radio"]')),l={},s=new Set;t.querySelectorAll('input[type="checkbox"]').forEach((e=>{const t=e.name;l[t]||(l[t]=[]),l[t].push(e),e.hasAttribute("required")&&s.add(t)}));t.querySelectorAll(".select2");let i=!0,o="This Field is Required.";if(t.querySelectorAll(".error-message").forEach((e=>{e.textContent="",e.classList.add("is-hidden")})),a.forEach((e=>{e.style.border=""})),a.forEach((e=>{const t=e.closest(".form-group")||e.parentNode;e.parentNode;if("date"==e.type){o="Please Select Date",e.style.border="";e.value.trim()||(i=!1,e.style.border="1px solid red",b(t,o))}else o="comments"==e.name?"Please Enter Comments":"email"==e.type?"Please Enter Email":"password"==e.type?"Please Enter Password":"This Field is Required.";const a=e.getAttribute("data-kilvish-name");let r;if(o=`${a||"This"} Field is Required.`,("tel"===e.type||e.hasAttribute("data-kilvish-tel"))&&(r=function(e){const t=e.closest(".kiltel-phone-wrap")||e.parentElement,a=t&&(t.querySelector('input[name="contact"]')||t.querySelector("#contact"));if(a)return(a.value||"").replace(/\D/g,"").length<7;const r=(e.value||"").trim().replace(/\s|-/g,"");return!r||(!!/^\+?$/.test(r)||(!!/^\+?\d{1,4}$/.test(r)||r.replace(/\D/g,"").length<7))}(e),r&&(o=`${a||"Phone"} is required (enter full number, not just country code).`)),r)return i=!1,e.style.border="1px solid red",void b(e,o);e.value.trim()||(i=!1,e.style.border="1px solid red",b(t,o))})),n.length>0){const e={};n.forEach((t=>{const a=t.name;e[a]||(e[a]={isSelected:!1,groupElement:t.closest(".form-group")||t.closest(".mb-3")||t.closest(".form-check")||t.closest(".radios")||t.closest(".col-md-6")}),t.checked&&(e[a].isSelected=!0)})),Object.entries(e).forEach((([e,t])=>{if(!t.isSelected){i=!1;const a="Please select one option.";if(!t.groupElement)return void console.error("Invalid group element for radio group:",e);b(t.groupElement,a)}}))}return Object.keys(l).forEach((e=>{const t=l[e];if(t.some((e=>e.hasAttribute("data-ignore-kilvish"))))return;if(!t.some((e=>e.checked))){i=!1;const a=s.has(e)?"Please check this box to proceed":"Please select at least one option.";b(t[0].closest(".form-group")||t[0].closest(".form-check")||t[0].closest(".checkbox-container")||t[0].closest(".some-other-container"),a)}})),i}function o(e){const t=r(e);if(!t)return;const a=t.querySelectorAll("input[required], select[required], textarea[required]"),n=(e,t=!0)=>{t?l(e):s(e)};function i(e){const t=e.form||e.closest("form");if(!t)return;const a=e.nextElementSibling;let r=e,n="afterend",l=e.name||e.id||"field";"SELECT"===e.tagName&&a&&(a.classList.contains("select2")||a.classList.contains("select2-container"))?(r=a,n="afterend",l=e.name||e.id||"select"):e.parentElement&&e.parentElement.classList.contains("input-group")&&(r=e.parentElement,n="afterend",l=e.name||e.id||"inputgroup");const i=t.querySelector(`#kil_err_${String(l).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);i&&(i.textContent="",i.classList.add("is-hidden")),e.style.border="",s(e)}a.forEach((e=>{if("1"===e.dataset.kilRealtimeBound)return;const t=()=>{e.value.trim()?(i(e),n(e,!1)):n(e,!0)};e.addEventListener("input",t),e.addEventListener("change",t),e.dataset.kilRealtimeBound="1"}));const o=t.querySelectorAll('input[type="radio"]');[...new Set(Array.from(o).map((e=>e.name)))].forEach((e=>{const a=t.querySelectorAll(`input[type="radio"][name="${e}"]`);a.forEach((e=>{"1"!==e.dataset.kilRadioBound&&(e.addEventListener("change",(()=>{Array.from(a).some((e=>e.checked))&&i(e)})),e.dataset.kilRadioBound="1")}))}));const d=t.querySelectorAll('input[type="checkbox"]');[...new Set(Array.from(d).map((e=>e.name)))].forEach((e=>{const a=t.querySelectorAll(`input[type="checkbox"][name="${e}"]`);a.forEach((e=>{"1"!==e.dataset.kilCheckboxBound&&(e.addEventListener("change",(()=>{Array.from(a).some((e=>e.checked))&&i(e)})),e.dataset.kilCheckboxBound="1")}))}))}function d(t,a){const r=i(t);if(!r){const t=a||e.event;t&&t.preventDefault&&t.preventDefault()}return r}function c(e=t){e.querySelectorAll("label, legend").forEach((e=>{e.querySelectorAll("span").forEach((e=>{e.classList.contains("kil-required-star")||"*"!==e.textContent.trim()||e.remove()}));const t=e.querySelectorAll(".kil-required-star");for(let e=1;e<t.length;e++)t[e].remove()}))}function u(){t.querySelectorAll("input[required], select[required], textarea[required]").forEach(l)}function p(){t.querySelectorAll("input, select, textarea").forEach((e=>{"1"!==e.dataset.kilInputBound&&(e.hasAttribute("data-ignore-kilvish")||(e.addEventListener("keyup",h),e.addEventListener("change",h),e.dataset.kilInputBound="1"))}))}function m(){t.querySelectorAll("form").forEach((e=>{const t=e.id;"1"!==e.dataset.kilFormSubmitBound&&(e.addEventListener("submit",(t=>d(e,t))),e.dataset.kilFormSubmitBound="1");const a=t?`#${t}`:e;e.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((e=>{"1"!==e.dataset.kilSubmitBound&&(e.addEventListener("click",(e=>d(a,e))),e.dataset.kilSubmitBound="1")}))}))}!function(){if(t.getElementById("kil-req-style"))return;const e=t.createElement("style");e.id="kil-req-style",e.textContent="\n .kil-required-star{ color:#d32f2f; margin-left:2px; }\n .error-message{ display:block; min-height:16px; margin-top:4px; font-size:12px; color:#d32f2f; line-height:1.25; opacity:1; transition:opacity .12s ease; }\n .error-message.is-hidden{ opacity:0; }\n ",t.head.appendChild(e)}();let y=null;function f(){c(),u();t.querySelectorAll("form").forEach((e=>{const t=e.id;o(t||e)})),p(),m(),g(),t.querySelectorAll('input[type="password"]').forEach(x),!y&&e.MutationObserver&&(y=new MutationObserver((e=>{for(const t of e)t.addedNodes&&t.addedNodes.forEach((e=>{e instanceof HTMLElement&&(e.matches&&e.matches('input[type="password"]')&&x(e),e.querySelectorAll&&e.querySelectorAll('input[type="password"]').forEach(x))}))})),y.observe(t.documentElement,{childList:!0,subtree:!0}))}function h(e){const a=e.target;if(a.hasAttribute("data-ignore-kilvish"))return;function r(e){const t=e.form||e.closest("form");if(!t)return;const a=e.nextElementSibling;let r=e.name||e.id||"field";"SELECT"===e.tagName&&a&&(a.classList.contains("select2")||a.classList.contains("select2-container"))?r=e.name||e.id||"select":e.parentElement&&e.parentElement.classList.contains("input-group")&&(r=e.name||e.id||"inputgroup");const n=t.querySelector(`#kil_err_${String(r).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);n&&(n.textContent="",n.classList.add("is-hidden")),e.style.border=""}let n=/^[a-zA-Z\s]*$/,l=!1;const s={image:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],doc:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pdf:["application/pdf"],mix:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],only_pdf_image:["application/pdf","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],only_doc_image:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"]},i={image:"Image",doc:"Document",pdf:"PDF",mix:"Image & Document",only_pdf_image:"PDF & Image",only_doc_image:"Document & Image"};if(r(a),"description"===a.name||"address"===a.name){if(l=!0,n=/^[a-zA-Z0-9@,._\s-'"*]*$/,a.value.length>400)return b(a,"Input exceeds the maximum length of 400 characters!"),a.style.border="1px solid red",void(a.value=a.value.substring(0,400))}else if("firstname"===a.name||"lastname"===a.name||"appointment_by"===a.name){l=!0,n=/^[a-zA-Z\s-]*$/;const t=/^[a-zA-Z0-9._@-\s]+$/,r=a.value;if(t.test(r)&&(r.length>20||r.length<2))return b(a,"This Field Must Be Between 2 And 20 Characters."),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("otp"===a.name){l=!0,n=/^\d{6}$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&6!==r.length)return b(a,"OTP must be exactly 6 digits"),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("number_of_items"===a.name){l=!0,n=/^\d{0,6}(\.\d{0,2})?$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&r.length>3)return b(a,"Pacakge Number Cannot Be Exceed 3 Digits"),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("contact"===a.name||"agent_contact"===a.id||"fullcontact"===a.name)l=!0,n=/^[\d\-\s]{0,20}$/;else if("number"===a.type){l=!0,n=/^\d{0,20}$/;const t=/^\d+$/,r=a.value;if(t.test(r)&&(r.length>20||r.length<1))return b(a,"This Must Be Between 1 And 20 Digits."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("tel"===a.type){l=!0;let t=a.value.trim().replace(/\s+/g,"");a.value=t;if(n=/^\+?\d{7,15}$/,!/^\+?\d{7,15}$/.test(t))return b(a,"Enter a valid phone number (7–15 digits, optional +)."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else if("kildate"===a.name){l=!0,n=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const t=a.value.trim(),r=new Date(t.replace(/[-\/]/g,"/")),s=new Date;s.setHours(0,0,0,0);const i=a.getAttribute("data-kilvish-date");if(i){const[t,n]=i.replace("_","").split("_").map(Number),l=new Date(s),o=new Date(s);if(l.setFullYear(s.getFullYear()-t),o.setFullYear(s.getFullYear()-n),r>l||r<o)return b(a,`Birthday cannot be less than ${t} years ago or more than ${n} years in the future.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(r<s)return b(a,"The date cannot be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}else{if("date"===a.type||"month"===a.type){l=!0,n=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=a.value.trim(),s="month"===a.type?new Date(r+"-01"):new Date(r.replace(/[-\/]/g,"/")),i=new Date;i.setHours(0,0,0,0);const o=a.getAttribute("data-kilvish-date");if(o)if(/^_(\d+)_(\d+)$/.test(o)){const[t,r]=o.replace("_","").split("_").map(Number),n=new Date(i),l=new Date(i);if(n.setFullYear(i.getFullYear()-t),l.setFullYear(i.getFullYear()-r),s>n||s<l)return b(a,`Age must be between ${t} and ${r} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^_(\d+)$/.test(o)){const t=Number(o.replace("_","")),r=new Date(i);if(r.setFullYear(i.getFullYear()-t),s.getTime()!==r.getTime())return b(a,`You must be exactly ${t} years old.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/future/.test(o)){if("future"===o&&s<=i)return b(a,"The selected date must be in the future."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("today_future"===o&&s<i)return b(a,"The selected date cannot be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/(\d+)_days_future/.test(o)){const t=Number(o.match(/(\d+)_days_future/)[1]),r=new Date(i);if(r.setDate(i.getDate()+t),s>r||s<i)return b(a,`The selected date must be within the next ${t} days.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_future$/.test(o)){const t=Number(o.match(/^(\d+)_years_future$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()+t),s<i||s>r)return b(a,`The date must be within the next ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_after$/.test(o)){const t=Number(o.match(/^(\d+)_years_after$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()+t),s.getTime()!==r.getTime())return b(a,`The date must be exactly ${t} years after today.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}else if(/past/.test(o)){if("past"===o&&s>=i)return b(a,"The selected date must be in the past."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/^(\d+)_years_past$/.test(o)){const t=Number(o.match(/^(\d+)_years_past$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()-t),s>i||s<r)return b(a,`The date must be within the past ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}else if(/^(\d+)_years_before$/.test(o)){const t=Number(o.match(/^(\d+)_years_before$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()-t),s>=r)return b(a,`The date must be before ${t} years ago.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_years_after$/.test(o)){const t=Number(o.match(/^(\d+)_years_after$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()+t),s<=r)return b(a,`The date must be after ${t} years from today.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/Between_(\d+)_(\d+)/.test(o)){const[t,r]=o.match(/Between_(\d+)_(\d+)/).slice(1,3).map(Number),n=new Date(t,0,1),l=new Date(r,11,31);if(s<n||s>l)return b(a,`The date must be between ${t} and ${r}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/from_(\d+)/.test(o)){const t=Number(o.match(/from_(\d+)/)[1]);if(s<new Date(t,0,1))return b(a,`The date must be from the year ${t} onwards.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/till_(\d+)/.test(o)){const t=Number(o.match(/till_(\d+)/)[1]);if(s>new Date(t,11,31))return b(a,`The date must be till the year ${t}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else{if("not_today"===o&&s.getTime()===i.getTime())return b(a,"Today's date is not allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("weekday"===o&&(0===s.getDay()||6===s.getDay()))return b(a,"Only weekdays (Monday to Friday) are allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("weekend"===o&&s.getDay()>=1&&s.getDay()<=5)return b(a,"Only weekends (Saturday and Sunday) are allowed."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if("first_of_month"===o&&1!==s.getDate())return b(a,"The date must be the first day of the month."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(/^exact_(\d+)$/.test(o)){const t=Number(o.match(/^exact_(\d+)$/)[1]),r=new Date(i);if(r.setFullYear(i.getFullYear()-t),s.getTime()!==r.getTime())return b(a,`You must be exactly ${t} years old.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if("last_of_month"===o){const t=new Date(s.getFullYear(),s.getMonth()+1,0).getDate();if(s.getDate()!==t)return b(a,"The date must be the last day of the month."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}const d=a.getAttribute("data-kilvish-dategroup");if(d&&/.+_[12]$/.test(d)){const[r,n]=d.split("_"),l="1"===n?"2":"1",s=t.querySelector(`[data-kilvish-dategroup="${r}_${l}"]`);if(s&&s.value){const t="month"===a.type?new Date(a.value+"-01"):new Date(a.value.replace(/[-\/]/g,"/")),i="month"===s.type?new Date(s.value+"-01"):new Date(s.value.replace(/[-\/]/g,"/"));if(!("1"===n&&t<=i||"2"===n&&t>=i)){const t=a.dataset.kilvishDate_name||`Field (${r}_${n})`,i=s.dataset.kilvishDate_name||`Field (${r}_${l})`;return b(a,`${t} must be ${"1"===n?"before or same as":"after or same as"} ${i}.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}}return void(a.style.border="")}if("age"===a.name){l=!0;const t=a.value.trim(),r=parseInt(t,10);if(isNaN(r))return b(a,"Please enter a valid number for age."),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));const n=a.getAttribute("data-kilvish-age")||"18";if(/^(\d+)$/.test(n)){const t=Number(n);if(r!==t)return b(a,`Age must be exactly ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}else if(/^(\d+)_(\d+)$/.test(n)){const[t,l]=n.split("_").map(Number);if(r<t)return b(a,`Minimum age must be ${t} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""));if(r>l)return b(a,`Age cannot exceed ${l} years.`),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}return void(a.style.border="")}}if("model_name"===a.name||"models[]"===a.name)l=!0,n=/^[a-zA-Z0-9]{4,20}$/;else if("email"===a.type){l=!0,n=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;const t=/^[a-zA-Z0-9._@-]+$/,r=a.value;if(t.test(r)&&!n.test(r))return b(a,"Invalid Email Format."),a.style.border="1px solid red",void("change"===e.type&&(a.value=""));a.style.border=""}if(a.hasAttribute("data-kilvish-num")){l=!0;const t=a.value,r=a.getAttribute("data-kilvish-num");n=/^[0-9]*$/;let s=null,i=null;const o=r.match(/^_(\d+)_(\d+)$/);o&&(s=parseInt(o[1],10),i=parseInt(o[2],10));const d=r.match(/^exact_(\d+)$/),c=d?parseInt(d[1],10):null;/^\d*$/.test(t)?null!==c&&t.length!==c?(b(a,`This field must contain exactly ${c} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):s&&t.length<s||i&&t.length>i?(b(a,`This Field Must be between ${s} and ${i} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):a.style.border="":(b(a,"Only numerical characters are allowed."),a.style.border="2px solid red")}if(a.hasAttribute("data-kilvish-num11")){l=!0;const t=a.value,r=a.getAttribute("data-kilvish-num");n=/^[0-9]*$/;let s=null,i=null;const o=r?r.match(/^_(\d+)_(\d+)$/):null;o&&(s=parseInt(o[1],10),i=parseInt(o[2],10)),"exact_20"===r&&(n=/^[0-9]{20}$/),n.test(t)?s&&t.length<s||i&&t.length>i?(b(a,`This Field Must be between ${s} and ${i} digits.`),a.style.border="2px solid red","change"===e.type&&(a.value="")):a.style.border="":(b(a,"exact_20"===r?"This field must contain exactly 20 digits.":"Only numerical characters are allowed."),a.style.border="2px solid red")}if(a.hasAttribute("data-kilvish-char")){l=!0;const t=a.value,r=a.getAttribute("data-kilvish-char");if(r.startsWith("Yes")||r.startsWith("mix")){"mix"===r?n=/^[a-zA-Z0-9]*$/:"Yes"===r&&(n=/^[a-zA-Z]*$/);const l=r.split("_").slice(1).join("");if(l&&(n=new RegExp(`^[a-zA-Z0-9${l}]*$`)),!n.test(t))return b(a,"Invalid character entered!"),a.style.border="2px solid red",void("change"===e.type&&(a.value=""))}}if(a.hasAttribute("data-kilvish-amount")){l=!0;const r=a.getAttribute("data-kilvish-amount");n=/^\d+(\.\d{0,2})?$/;let s="USD",i=null,o=null;const d=r.match(/^([A-Z]{3})(?:_(\d+)_(\d+))?$/);d&&(s=d[1],i=d[2]?parseFloat(d[2]):null,o=d[3]?parseFloat(d[3]):null);const c=()=>{let e=a.selectionStart,r=a.value;n.test(r)||(r=r.replace(/[^0-9.]/g,"").replace(/(\..*?)\..*/,"$1").replace(/(\.\d{2}).*/,"$1")),!r||r.includes(".")||r.endsWith(".")||(r=parseFloat(r).toFixed(2)),a.value=r;const l=r.indexOf(".");-1!==l&&e>l&&(e=Math.min(e,r.length)),a.setSelectionRange(e,e);let i=a.nextElementSibling;i&&i.classList.contains("amount-display")||(i=t.createElement("div"),i.className="amount-display",i.style.color="green",a.parentNode.insertBefore(i,a.nextSibling)),i.textContent=`${s} ${r||"0.00"} .`},u=()=>{if(a.readOnly)return;let e=parseFloat(a.value||"0").toFixed(2),t=a.nextElementSibling;return null!==i&&e<i?(b(a,`Amount must be at least ${i.toFixed(2)} ${s}.`),a.style.border="2px solid red",a.value="",void(t&&(t.textContent=""))):null!==o&&e>o?(b(a,`Amount must not exceed ${o.toFixed(2)} ${s}.`),a.style.border="2px solid red",a.value="",void(t&&(t.textContent=""))):(a.style.border="",void(a.value=e))};"1"!==a.dataset.kilAmountBound&&(a.addEventListener("input",c),a.addEventListener("blur",u),a.dataset.kilAmountBound="1"),"keyup"!==e.type&&"change"!==e.type||c()}if("password"===a.type){l=!0;const{bars:r,label:s,rulesUl:i}=v(a),o=a.getAttribute("data-kilvish-password")||"12",[d,c]=o.split("_"),u=parseInt(d,10)||12,p=parseInt(c||"128",10);n=new RegExp(`^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[\\W_]).{${u},${p}}$`);const m={length:`Password must be between ${u} and ${p} characters long`,uppercase:"At least one uppercase letter (A-Z)",lowercase:"At least one lowercase letter (a-z)",number:"At least one number (0-9)",special:"At least one special character (!@#$%^&*)",sequential:"No sequential characters (e.g., 1234, abcd)"},y={};Object.keys(m).forEach((e=>{let a=i.querySelector(`li[data-rule="${e}"]`);a||(a=t.createElement("li"),a.setAttribute("data-rule",e),a.textContent=`❌ ${m[e]}`,a.style.color="red",a.style.fontSize="12px",i.appendChild(a)),y[e]=a}));const f=e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1},h=e=>{let t=0;return e.length>=u&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),f(e)&&(t-=2),Math.max(0,t)},g=a.value||"",b={length:g.length>=u&&g.length<=p,uppercase:/[A-Z]/.test(g),lowercase:/[a-z]/.test(g),number:/\d/.test(g),special:/[\W_]/.test(g),sequential:!f(g)};Object.keys(b).forEach((e=>{const t=b[e];y[e].textContent=`${t?"✅":"❌"} ${m[e]}`,y[e].style.color=t?"green":"red"}));const x=h(g);r.forEach((e=>e.style.background="lightgray")),x<=2?(r[0]&&(r[0].style.background="red"),s.textContent="Weak",s.style.color="red"):x<=4?(r[0]&&(r[0].style.background="yellow"),r[1]&&(r[1].style.background="yellow"),s.textContent="Medium",s.style.color="orange"):(r[0]&&(r[0].style.background="green"),r[1]&&(r[1].style.background="green"),r[2]&&(r[2].style.background="green"),s.textContent="Strong",s.style.color="green");const k=n.test(g)&&Object.values(b).every(Boolean);return a.style.border=k?"1px solid green":"1px solid red",void(k||"change"!==e.type||(a.value=""))}if("file"===a.type){l=!0;const e=a.getAttribute("data-kilvish-file")||"image",[t,...r]=e.split("_"),n=s[e]||s[t]||s.image,o=a.files;let d=1,c=1/0;if(r.length>=2&&(d=parseInt(r[0],10),c=parseInt(r[1],10)),o.length<d||o.length>c)return b(a,`Please select between ${d} and ${c} valid file(s).`),a.value="",a.style.border="1px solid red",!1;const u=i[e]||t.toUpperCase();for(const e of o)if(!n.includes(e.type))return b(a,`Invalid file type. Allowed types: ${u}.`),a.value="",a.style.border="1px solid red",!1}else l&&("keyup"===e.type&&(n.test(a.value)||("password"!==a.type&&b(a,"Invalid character entered!"),a.style.border="1px solid red")),"change"===e.type&&(n.test(a.value)?(a.style.border="",r(a)):(a.value="",b(a,"Invalid character or format!"),a.style.border="1px solid red")))}function g(){t.querySelectorAll("input[type='password']").forEach((e=>{if(e.hasAttribute("data-ignore-kilvish"))return;if("1"===e.dataset.kilPassStrengthBound)return;const{bars:t,label:a}=v(e),r=e.getAttribute("data-kilvish-password")||"12",[n]=r.split("_").map(Number);e.addEventListener("input",(e=>{const r=(e=>{let t=0;return e.length>=n&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),(e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1})(e)&&(t-=2),Math.max(0,t)})(e.target.value);t.forEach((e=>e.style.background="lightgray")),r<=2?(t[0].style.background="red",a.textContent="Weak",a.style.color="red"):r<=4?(t[0].style.background="yellow",t[1].style.background="yellow",a.textContent="Medium",a.style.color="orange"):(t[0].style.background="green",t[1].style.background="green",t[2].style.background="green",a.textContent="Strong",a.style.color="green")})),e.dataset.kilPassStrengthBound="1"}))}function b(e,a){const r=e.form?e.form:e.closest("form");if(!r)return;let n=null;if(e&&e.tagName&&/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName))n=e;else if(e&&e.querySelector){const t=e.querySelectorAll("input,select,textarea");n=t.length?t[t.length-1]:null}let s=e,i="beforeend",o="container";if(n){const e=n.nextElementSibling;"SELECT"===n.tagName&&e&&(e.classList.contains("select2")||e.classList.contains("select2-container"))?(s=e,i="afterend",o=n.name||n.id||"select"):n.parentElement&&n.parentElement.classList.contains("input-group")?(s=n.parentElement,i="afterend",o=n.name||n.id||"inputgroup"):(s=n,i="afterend",o=n.name||n.id||"field")}const d=`kil_err_${String(o).replace(/[^a-zA-Z0-9_\-]/g,"_")}`;let c=r.querySelector(`#${d}`);if(c||(c=t.createElement("div"),c.id=d,c.className="error-message is-hidden","beforeend"===i?s.insertAdjacentElement("beforeend",c):s.insertAdjacentElement("afterend",c)),c.textContent=a||"",c.classList.remove("is-hidden"),n)l(n);else{const t=e.querySelector("input[required],select[required],textarea[required]")||e.querySelector("input,select,textarea");t&&l(t)}}function v(e){const a=function(e){return e.parentElement&&e.parentElement.classList.contains("input-group")?e.parentElement:e}(e),r=e.name||e.id||"password",n=`kil_passui_${String(r).replace(/[^a-zA-Z0-9_-]/g,"_")}`;let l=a.parentNode.querySelector(`#${n}`);if(!l){l=t.createElement("div"),l.id=n,l.className="kil-passui";const e=t.createElement("div");e.className="password-strength";const r=t.createElement("div");r.className="bars";const s=t.createElement("div");s.className="bar";const i=t.createElement("div");i.className="bar";const o=t.createElement("div");o.className="bar",r.append(s,i,o);const d=t.createElement("span");d.className="label",d.textContent="Weak",d.style.fontSize="12px",e.append(r,d);const c=t.createElement("ul");c.className="password-validation",l.append(e,c),a.insertAdjacentElement("afterend",l)}const s=l.querySelectorAll(".bar"),i=l.querySelector(".password-strength .label"),o=l.querySelector(".password-validation");return{wrap:l,bars:s,label:i,rulesUl:o}}function x(e){if("1"===e.dataset.kileyeAttached)return;if(e.hasAttribute("data-kileye-false"))return;const{anchor:a}=function(e){const a=e.closest(".input-group");if(a)return a.classList.add("kil-eye-rel"),e.classList.add("kil-eye-pad"),{anchor:a};if(!e.parentElement.classList.contains("kil-eye-wrap")){const a=t.createElement("span");a.className="kil-eye-wrap",e.parentNode.insertBefore(a,e),a.appendChild(e)}return e.classList.add("kil-eye-pad"),{anchor:e.parentElement}}(e);a.style.overflow="visible";let r=a.querySelector(".kil-eye-btn");r||(r=t.createElement("button"),r.type="button",r.className="kil-eye-btn",r.setAttribute("tabindex","-1"),r.setAttribute("aria-label","Show/Hide password"),r.innerHTML='<i class="fa fa-eye-slash" aria-hidden="true"></i>',a.appendChild(r));const n=e.getAttribute("data-kileye-color");n&&(r.style.color=n);const l=()=>r.querySelector("i");function s(){e.type="text",l()&&(l().classList.remove("fa-eye-slash"),l().classList.add("fa-eye"))}function i(){e.type="password",l()&&(l().classList.remove("fa-eye"),l().classList.add("fa-eye-slash"))}function o(){"password"===e.type?s():i()}const d=(e.getAttribute("data-kileye-show")||"hold").toLowerCase(),c=(e.getAttribute("data-kileye-initial")||"auto").toLowerCase();"fix"===d||"on"===c?s():"off"!==c&&"auto"!==c||i(),r.onmousedown=r.onmouseup=r.onmouseleave=r.onclick=null,r.ontouchstart=r.ontouchend=r.ontouchcancel=null,"toggle"===d||"fix"===d?(r.onclick=e=>{e.preventDefault(),o()},r.addEventListener("touchstart",(e=>{e.preventDefault(),o()}),{passive:!1})):(r.onmousedown=e=>{e.preventDefault(),s()},r.onmouseup=()=>i(),r.onmouseleave=()=>i(),r.onblur=()=>i(),r.addEventListener("touchstart",(e=>{e.preventDefault(),s()}),{passive:!1}),r.addEventListener("touchend",(()=>i())),r.addEventListener("touchcancel",(()=>i()))),e.addEventListener("blur",(()=>{"hold"===d&&i()})),e.dataset.kileyeAttached="1"}return"loading"===t.readyState?t.addEventListener("DOMContentLoaded",f):f(),function(){if(t.getElementById("kil-pass-style"))return;const e=t.createElement("style");e.id="kil-pass-style",e.textContent="\n .kil-passui { display:block; width:100%; margin-top:6px; }\n .kil-passui .password-strength { display:flex; align-items:center; gap:10px; }\n .kil-passui .password-strength .bars { display:flex; gap:4px; }\n .kil-passui .password-strength .bar { height:5px; width:30px; border-radius:3px; background:lightgray; }\n .kil-passui .password-validation { list-style:none; padding:0; margin:6px 0 0; }\n .kil-passui .password-validation li { font-size:12px; margin:2px 0; }\n ",t.head.appendChild(e)}(),function(){if(t.getElementById("kil-eye-style"))return;const e=t.createElement("style");e.id="kil-eye-style",e.textContent="\n .kil-eye-rel { position: relative !important; overflow: visible !important; }\n .kil-eye-wrap{ position:relative; display:block; }\n .kil-eye-btn{\n position:absolute; top:50%; right:10px; transform:translateY(-50%);\n display:inline-flex; align-items:center; justify-content:center;\n background:transparent; border:0; padding:0; margin:0;\n height:auto; width:auto; line-height:1; cursor:pointer; outline:none;\n z-index: 10; /* <-- stays above focused input */\n pointer-events: auto;\n }\n .kil-eye-btn i{ font-size:16px; }\n .kil-eye-pad { padding-right: 38px !important; }\n .kil-eye-btn { flex: 0 0 auto; }\n ",t.head.appendChild(e)}(),{validateRequiredFields:i,addRealTimeValidation:o,validateForm:d,addAsteriskToRequiredFields:u,attachInputEvents:p,addValidateFormToSubmitButtons:m,validateKilvishInput:h,addErrorMessage:b,init:f,initPasswordStrengthMeter:g,normalizeRequiredStars:c}}));
|
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 n=`kil_err_${_escKey(a)}`;let s=e.querySelector(`#${n}`);return s||(s=document.createElement("div"),s.id=n,s.className="error-message is-hidden","beforeend"===r?t.insertAdjacentElement("beforeend",s):t.insertAdjacentElement("afterend",s)),s}function findLabelFor(e){if(!e)return null;const t=e.form||document;let r=null;if(e.id&&(r=t.querySelector(`label[for="${CSS.escape(e.id)}"]`)),!r&&e.name&&(r=t.querySelector(`label[for="${CSS.escape(e.name)}"]`)),r||(r=e.closest("label")),!r){const t=e.closest("fieldset");t&&(r=t.querySelector("legend"))}return r}function ensureStarVisibleFor(e){const t=findLabelFor(e);if(!t)return;let r=t.querySelector(".kil-required-star");r||(r=document.createElement("span"),r.className="kil-required-star",r.textContent=" *",t.appendChild(r)),r.style.visibility="visible"}function hideStarFor(e){const t=findLabelFor(e);if(!t)return;const r=t.querySelector(".kil-required-star");r&&(r.style.visibility="hidden")}function isKiltelEmpty(e){const t=e.closest(".kiltel-phone-wrap")||e.parentElement,r=t&&(t.querySelector('input[name="contact"]')||t.querySelector("#contact"));if(r){return(r.value||"").replace(/\D/g,"").length<7}const a=(e.value||"").trim().replace(/\s|-/g,"");if(!a)return!0;if(/^\+?$/.test(a))return!0;if(/^\+?\d{1,4}$/.test(a))return!0;return a.replace(/\D/g,"").length<7}function validateRequiredFields(e){const t=document.querySelector(`${e}`),r=t.querySelectorAll("input[required], select[required], textarea[required]"),a=(t.querySelectorAll("fieldset.radios"),t.querySelectorAll('input[type="radio"]')),n={},s=new Set;t.querySelectorAll('input[type="checkbox"]').forEach((e=>{const t=e.name;n[t]||(n[t]=[]),n[t].push(e),e.hasAttribute("required")&&s.add(t)}));t.querySelectorAll(".select2");let o=!0,l="This Field is Required.";if(t.querySelectorAll(".error-message").forEach((e=>{e.textContent="",e.classList.add("is-hidden")})),r.forEach((e=>{e.style.border=""})),r.forEach((e=>{const t=e.closest(".form-group")||e.parentNode;e.parentNode;if("date"==e.type){l="Please Select Date",e.style.border="";e.value.trim()||(o=!1,e.style.border="1px solid red",addErrorMessage(t,l))}else l="comments"==e.name?"Please Enter Comments":"email"==e.type?"Please Enter Email":"password"==e.type?"Please Enter Password":"This Field is Required.";const r=e.getAttribute("data-kilvish-name");let a;if(l=`${r||"This"} Field is Required.`,("tel"===e.type||e.hasAttribute("data-kilvish-tel"))&&(a=isKiltelEmpty(e),a&&(l=`${r||"Phone"} is required (enter full number, not just country code).`)),a)return o=!1,e.style.border="1px solid red",void addErrorMessage(e,l);e.value.trim()||(o=!1,e.style.border="1px solid red",addErrorMessage(t,l))})),a.length>0){const e={};a.forEach((t=>{const r=t.name;e[r]||(e[r]={isSelected:!1,groupElement:t.closest(".form-group")||t.closest(".mb-3")||t.closest(".form-check")||t.closest(".radios")||t.closest(".col-md-6")}),t.checked&&(e[r].isSelected=!0)})),Object.entries(e).forEach((([e,t])=>{if(!t.isSelected){o=!1;const r="Please select one option.";if(!t.groupElement)return void console.error("Invalid group element for radio group:",e);addErrorMessage(t.groupElement,r)}}))}return Object.keys(n).forEach((e=>{const t=n[e];if(t.some((e=>e.hasAttribute("data-ignore-kilvish"))))return;if(!t.some((e=>e.checked))){o=!1;const r=s.has(e)?"Please check this box to proceed":"Please select at least one option.";addErrorMessage(t[0].closest(".form-group")||t[0].closest(".form-check")||t[0].closest(".checkbox-container")||t[0].closest(".some-other-container"),r)}})),o}function addRealTimeValidation(e){const t=document.getElementById(e),r=t.querySelectorAll("input[required], select[required], textarea[required]"),a=(e,r=!0)=>{let a=t.querySelector(`label[for='${e.name}']`);if(!a){const t=e.closest("fieldset");t&&(a=t.querySelector("legend"))}a&&(r&&!a.innerHTML.includes("*")?a.innerHTML+=' <span style="color:red;">*</span>':!r&&a.innerHTML.includes("*")&&(a.innerHTML=a.innerHTML.replace(' <span style="color:red;">*</span>',"")))};r.forEach((e=>{const t=()=>{e.value.trim()?(!function(e){const t=e.form||e.closest("form");if(!t)return;const r=e.nextElementSibling;let a=e,n="afterend",s=e.name||e.id||"field";"SELECT"===e.tagName&&r&&(r.classList.contains("select2")||r.classList.contains("select2-container"))?(a=r,n="afterend",s=e.name||e.id||"select"):e.parentElement&&e.parentElement.classList.contains("input-group")&&(a=e.parentElement,n="afterend",s=e.name||e.id||"inputgroup");const o=t.querySelector(`#kil_err_${String(s).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);o&&(o.textContent="",o.classList.add("is-hidden")),e.style.border="",hideStarFor(e)}(e),a(e,!1)):a(e,!0)};e.addEventListener("input",t),e.addEventListener("change",t)}));const n=t.querySelectorAll('input[type="radio"]');[...new Set(Array.from(n).map((e=>e.name)))].forEach((e=>{const r=t.querySelectorAll(`input[type="radio"][name="${e}"]`);r.forEach((e=>{e.addEventListener("change",(()=>{if(Array.from(r).some((e=>e.checked))){const t=e.closest(".form-group")||e.closest(".form-check")||e.closest(".radios")||e.closest(".mb-3")||e.closest(".col-md-6"),r=t?.querySelector(".error-message");r&&r.remove()}}))}))}));const s=t.querySelectorAll('input[type="checkbox"]');[...new Set(Array.from(s).map((e=>e.name)))].forEach((e=>{const r=t.querySelectorAll(`input[type="checkbox"][name="${e}"]`);r.forEach((e=>{e.addEventListener("change",(()=>{if(Array.from(r).some((e=>e.checked))){const t=e.closest(".form-group")||e.closest(".form-check")||e.closest(".checkbox-container")||e.closest(".some-other-container"),r=t?.querySelector(".error-message");r&&r.remove()}}))}))}))}function validateForm(e){validateRequiredFields(e)||event.preventDefault()}function normalizeRequiredStars(e=document){e.querySelectorAll("label, legend").forEach((e=>{e.querySelectorAll("span").forEach((e=>{e.classList.contains("kil-required-star")||"*"!==e.textContent.trim()||e.remove()}));const t=e.querySelectorAll(".kil-required-star");for(let e=1;e<t.length;e++)t[e].remove()}))}function addAsteriskToRequiredFields_working(){document.querySelectorAll("input, select, textarea").forEach((e=>{if(e.required){let t;if(t=document.querySelector(`label[for='${e.name}']`),!t){const r=e.closest("fieldset");r&&(t=r.querySelector("legend"))}t&&!t.innerHTML.includes("*")&&(t.innerHTML+=' <span style="color:red;">*</span>')}}))}function addAsteriskToRequiredFields(){document.querySelectorAll("input[required], select[required], textarea[required]").forEach(ensureStarVisibleFor)}function attachInputEvents(){document.querySelectorAll("input, select, textarea").forEach((e=>{e.hasAttribute("data-ignore-kilvish")||(e.addEventListener("keyup",validateKilvishInput),e.addEventListener("change",validateKilvishInput))}))}function addValidateFormToSubmitButtons(){document.querySelectorAll("form").forEach((e=>{const t=e.id;if(t){e.querySelectorAll('button[type="submit"], input[type="submit"]').forEach((e=>{e.setAttribute("onclick",`validateForm('#${t}')`)}))}else console.warn("Form without ID found. Skipping validation.")}))}function validateKilvishInput(e){const t=e.target;function r(e){const t=e.form||e.closest("form");if(!t)return;const r=e.nextElementSibling;let a=e.name||e.id||"field";"SELECT"===e.tagName&&r&&(r.classList.contains("select2")||r.classList.contains("select2-container"))?a=e.name||e.id||"select":e.parentElement&&e.parentElement.classList.contains("input-group")&&(a=e.name||e.id||"inputgroup");const n=t.querySelector(`#kil_err_${String(a).replace(/[^a-zA-Z0-9_\-]/g,"_")}`);n&&(n.textContent="",n.classList.add("is-hidden")),e.style.border=""}let a=/^[a-zA-Z\s]*$/,n=!1;const s={image:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],doc:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],pdf:["application/pdf"],mix:["image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],only_pdf_image:["application/pdf","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"],only_doc_image:["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","image/jpeg","image/png","image/bmp","image/tiff","image/webp","image/svg+xml"]},o={image:"Image",doc:"Document",pdf:"PDF",mix:"Image & Document",only_pdf_image:"PDF & Image",only_doc_image:"Document & Image"};if(r(t),"description"===t.name||"address"===t.name){if(n=!0,a=/^[a-zA-Z0-9@,._\s-'"*]*$/,t.value.length>400)return addErrorMessage(t,"Input exceeds the maximum length of 400 characters!"),t.style.border="1px solid red",void(t.value=t.value.substring(0,400))}else if("firstname"===t.name||"lastname"===t.name||"appointment_by"===t.name){n=!0,a=/^[a-zA-Z\s-]*$/;const r=/^[a-zA-Z0-9._@-\s]+$/,s=t.value;if(r.test(s)&&(s.length>20||s.length<2))return addErrorMessage(t,"This Field Must Be Between 2 And 20 Characters."),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("otp"===t.name){n=!0,a=/^\d{6}$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&6!==s.length)return addErrorMessage(t,"OTP must be exactly 6 digits"),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("number_of_items"===t.name){n=!0,a=/^\d{0,6}(\.\d{0,2})?$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&s.length>3)return addErrorMessage(t,"Pacakge Number Cannot Be Exceed 3 Digits"),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("contact"===t.name||"agent_contact"===t.id||"fullcontact"===t.name)n=!0,a=/^[\d\-\s]{0,20}$/;else if("number"===t.type){n=!0,a=/^\d{0,20}$/;const r=/^\d+$/,s=t.value;if(r.test(s)&&(s.length>20||s.length<1))return addErrorMessage(t,"This Must Be Between 1 And 20 Digits."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("tel"===t.type){n=!0;let r=t.value.trim().replace(/\s+/g,"");t.value=r;if(a=/^\+?\d{7,15}$/,!/^\+?\d{7,15}$/.test(r))return addErrorMessage(t,"Enter a valid phone number (7–15 digits, optional +)."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else if("kildate"===t.name){n=!0,a=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=t.value.trim(),s=new Date(r.replace(/[-\/]/g,"/")),o=new Date;o.setHours(0,0,0,0);const l=t.getAttribute("data-kilvish-date");if(l){const[r,a]=l.replace("_","").split("_").map(Number),n=new Date(o),i=new Date(o);if(n.setFullYear(o.getFullYear()-r),i.setFullYear(o.getFullYear()-a),s>n||s<i)return addErrorMessage(t,`Birthday cannot be less than ${r} years ago or more than ${a} years in the future.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(s<o)return addErrorMessage(t,"The date cannot be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}else{if("date"===t.type||"month"===t.type){n=!0,a=/^(?:\d{4}[-\/]\d{2}[-\/]\d{2})$/;const r=t.value.trim(),s="month"===t.type?new Date(r+"-01"):new Date(r.replace(/[-\/]/g,"/")),o=new Date;o.setHours(0,0,0,0);const l=t.getAttribute("data-kilvish-date");if(l)if(/^_(\d+)_(\d+)$/.test(l)){const[r,a]=l.replace("_","").split("_").map(Number),n=new Date(o),i=new Date(o);if(n.setFullYear(o.getFullYear()-r),i.setFullYear(o.getFullYear()-a),s>n||s<i)return addErrorMessage(t,`Age must be between ${r} and ${a} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^_(\d+)$/.test(l)){const r=Number(l.replace("_","")),a=new Date(o);if(a.setFullYear(o.getFullYear()-r),s.getTime()!==a.getTime())return addErrorMessage(t,`You must be exactly ${r} years old.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/future/.test(l)){if("future"===l&&s<=o)return addErrorMessage(t,"The selected date must be in the future."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("today_future"===l&&s<o)return addErrorMessage(t,"The selected date cannot be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/(\d+)_days_future/.test(l)){const r=Number(l.match(/(\d+)_days_future/)[1]),a=new Date(o);if(a.setDate(o.getDate()+r),s>a||s<o)return addErrorMessage(t,`The selected date must be within the next ${r} days.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_future$/.test(l)){const r=Number(l.match(/^(\d+)_years_future$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()+r),s<o||s>a)return addErrorMessage(t,`The date must be within the next ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_after$/.test(l)){const r=Number(l.match(/^(\d+)_years_after$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()+r),s.getTime()!==a.getTime())return addErrorMessage(t,`The date must be exactly ${r} years after today.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}else if(/past/.test(l)){if("past"===l&&s>=o)return addErrorMessage(t,"The selected date must be in the past."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/^(\d+)_years_past$/.test(l)){const r=Number(l.match(/^(\d+)_years_past$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()-r),s>o||s<a)return addErrorMessage(t,`The date must be within the past ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}else if(/^(\d+)_years_before$/.test(l)){const r=Number(l.match(/^(\d+)_years_before$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()-r),s>=a)return addErrorMessage(t,`The date must be before ${r} years ago.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_years_after$/.test(l)){const r=Number(l.match(/^(\d+)_years_after$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()+r),s<=a)return addErrorMessage(t,`The date must be after ${r} years from today.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/Between_(\d+)_(\d+)/.test(l)){const[r,a]=l.match(/Between_(\d+)_(\d+)/).slice(1,3).map(Number),n=new Date(r,0,1),o=new Date(a,11,31);if(s<n||s>o)return addErrorMessage(t,`The date must be between ${r} and ${a}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/from_(\d+)/.test(l)){const r=Number(l.match(/from_(\d+)/)[1]);if(s<new Date(r,0,1))return addErrorMessage(t,`The date must be from the year ${r} onwards.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/till_(\d+)/.test(l)){const r=Number(l.match(/till_(\d+)/)[1]);if(s>new Date(r,11,31))return addErrorMessage(t,`The date must be till the year ${r}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else{if("not_today"===l&&s.getTime()===o.getTime())return addErrorMessage(t,"Today's date is not allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("weekday"===l&&(0===s.getDay()||6===s.getDay()))return addErrorMessage(t,"Only weekdays (Monday to Friday) are allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("weekend"===l&&s.getDay()>=1&&s.getDay()<=5)return addErrorMessage(t,"Only weekends (Saturday and Sunday) are allowed."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if("first_of_month"===l&&1!==s.getDate())return addErrorMessage(t,"The date must be the first day of the month."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(/^exact_(\d+)$/.test(l)){const r=Number(l.match(/^exact_(\d+)$/)[1]),a=new Date(o);if(a.setFullYear(o.getFullYear()-r),s.getTime()!==a.getTime())return addErrorMessage(t,`You must be exactly ${r} years old.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if("last_of_month"===l){const r=new Date(s.getFullYear(),s.getMonth()+1,0).getDate();if(s.getDate()!==r)return addErrorMessage(t,"The date must be the last day of the month."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}const i=t.getAttribute("data-kilvish-dategroup");if(i&&/.+_[12]$/.test(i)){const[r,a]=i.split("_"),n="1"===a?"2":"1",s=document.querySelector(`[data-kilvish-dategroup="${r}_${n}"]`);if(s&&s.value){const o="month"===t.type?new Date(t.value+"-01"):new Date(t.value.replace(/[-\/]/g,"/")),l="month"===s.type?new Date(s.value+"-01"):new Date(s.value.replace(/[-\/]/g,"/"));if(!("1"===a&&o<=l||"2"===a&&o>=l)){const o=t.dataset.kilvishDate_name||`Field (${r}_${a})`,l=s.dataset.kilvishDate_name||`Field (${r}_${n})`;return addErrorMessage(t,`${o} must be ${"1"===a?"before or same as":"after or same as"} ${l}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}}return void(t.style.border="")}if("age"===t.name){n=!0;const r=t.value.trim(),a=parseInt(r,10);if(isNaN(a))return addErrorMessage(t,"Please enter a valid number for age."),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));const s=t.getAttribute("data-kilvish-age")||"18";if(/^(\d+)$/.test(s)){const r=Number(s);if(a!==r)return addErrorMessage(t,`Age must be exactly ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}else if(/^(\d+)_(\d+)$/.test(s)){const[r,n]=s.split("_").map(Number);if(a<r)return addErrorMessage(t,`Minimum age must be ${r} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""));if(a>n)return addErrorMessage(t,`Age cannot exceed ${n} years.`),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}return void(t.style.border="")}}if("model_name"===t.name||"models[]"===t.name)n=!0,a=/^[a-zA-Z0-9]{4,20}$/;else if("email"===t.type){n=!0,a=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;const r=/^[a-zA-Z0-9._@-]+$/,s=t.value;if(r.test(s)&&!a.test(s))return addErrorMessage(t,"Invalid Email Format."),t.style.border="1px solid red",void("change"===e.type&&(t.value=""));t.style.border=""}if(t.hasAttribute("data-kilvish-num")){n=!0;const r=t.value,s=t.getAttribute("data-kilvish-num");a=/^[0-9]*$/;let o=null,l=null;const i=s.match(/^_(\d+)_(\d+)$/);i&&(o=parseInt(i[1],10),l=parseInt(i[2],10));const d=s.match(/^exact_(\d+)$/),c=d?parseInt(d[1],10):null;/^\d*$/.test(r)?null!==c&&r.length!==c?(addErrorMessage(t,`This field must contain exactly ${c} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):o&&r.length<o||l&&r.length>l?(addErrorMessage(t,`This Field Must be between ${o} and ${l} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):t.style.border="":(addErrorMessage(t,"Only numerical characters are allowed."),t.style.border="2px solid red")}if(t.hasAttribute("data-kilvish-num11")){n=!0;const r=t.value,s=t.getAttribute("data-kilvish-num");a=/^[0-9]*$/;let o=null,l=null;const i=s?s.match(/^_(\d+)_(\d+)$/):null;i&&(o=parseInt(i[1],10),l=parseInt(i[2],10)),"exact_20"===s&&(a=/^[0-9]{20}$/),a.test(r)?o&&r.length<o||l&&r.length>l?(addErrorMessage(t,`This Field Must be between ${o} and ${l} digits.`),t.style.border="2px solid red","change"===e.type&&(t.value="")):t.style.border="":(addErrorMessage(t,"exact_20"===s?"This field must contain exactly 20 digits.":"Only numerical characters are allowed."),t.style.border="2px solid red")}if(t.hasAttribute("data-kilvish-char")){n=!0;const r=t.value,s=t.getAttribute("data-kilvish-char");if(s.startsWith("Yes")||s.startsWith("mix")){"mix"===s?a=/^[a-zA-Z0-9]*$/:"Yes"===s&&(a=/^[a-zA-Z]*$/);const n=s.split("_").slice(1).join("");if(n&&(a=new RegExp(`^[a-zA-Z0-9${n}]*$`)),!a.test(r))return addErrorMessage(t,"Invalid character entered!"),t.style.border="2px solid red",void("change"===e.type&&(t.value=""))}}if(t.hasAttribute("data-kilvish-amount")){n=!0;const r=t.getAttribute("data-kilvish-amount");a=/^\d+(\.\d{0,2})?$/;let s="USD",o=null,l=null;const i=r.match(/^([A-Z]{3})(?:_(\d+)_(\d+))?$/);i&&(s=i[1],o=i[2]?parseFloat(i[2]):null,l=i[3]?parseFloat(i[3]):null),t.addEventListener("input",(()=>{let e=t.selectionStart,r=t.value;a.test(r)||(r=r.replace(/[^0-9.]/g,"").replace(/(\..*?)\..*/,"$1").replace(/(\.\d{2}).*/,"$1")),!r||r.includes(".")||r.endsWith(".")||(r=parseFloat(r).toFixed(2)),t.value=r;const n=r.indexOf(".");-1!==n&&e>n&&(e=Math.min(e,r.length)),t.setSelectionRange(e,e);let o=t.nextElementSibling;o&&o.classList.contains("amount-display")||(o=document.createElement("div"),o.className="amount-display",o.style.color="green",t.parentNode.insertBefore(o,t.nextSibling)),o.textContent=`${s} ${r||"0.00"} .`})),t.addEventListener("blur",(()=>{if(t.readOnly)return;let r=parseFloat(t.value||"0").toFixed(2),a=t.nextElementSibling;return null!==o&&r<o?(addErrorMessage(t,`Amount must be at least ${o.toFixed(2)} ${s}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value="",a&&(a.textContent="")))):null!==l&&r>l?(addErrorMessage(t,`Amount must not exceed ${l.toFixed(2)} ${s}.`),t.style.border="2px solid red",void("change"===e.type&&(t.value="",a&&(a.textContent="")))):(t.style.border="",void(t.value=r))}))}if("password"===t.type){n=!0;const{bars:r,label:s,rulesUl:o}=ensurePassUI(t),l=t.getAttribute("data-kilvish-password")||"12",[i,d]=l.split("_"),c=parseInt(i,10)||12,u=parseInt(d||"128",10);a=new RegExp(`^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[\\W_]).{${c},${u}}$`);const p={length:`Password must be between ${c} and ${u} characters long`,uppercase:"At least one uppercase letter (A-Z)",lowercase:"At least one lowercase letter (a-z)",number:"At least one number (0-9)",special:"At least one special character (!@#$%^&*)",sequential:"No sequential characters (e.g., 1234, abcd)"},m={};Object.keys(p).forEach((e=>{let t=o.querySelector(`li[data-rule="${e}"]`);t||(t=document.createElement("li"),t.setAttribute("data-rule",e),t.textContent=`❌ ${p[e]}`,t.style.color="red",t.style.fontSize="12px",o.appendChild(t)),m[e]=t}));const g=e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1},y=e=>{let t=0;return e.length>=c&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),g(e)&&(t-=2),Math.max(0,t)},f=t.value||"",h={length:f.length>=c&&f.length<=u,uppercase:/[A-Z]/.test(f),lowercase:/[a-z]/.test(f),number:/\d/.test(f),special:/[\W_]/.test(f),sequential:!g(f)};Object.keys(h).forEach((e=>{const t=h[e];m[e].textContent=`${t?"✅":"❌"} ${p[e]}`,m[e].style.color=t?"green":"red"}));const b=y(f);r.forEach((e=>e.style.background="lightgray")),b<=2?(r[0]&&(r[0].style.background="red"),s.textContent="Weak",s.style.color="red"):b<=4?(r[0]&&(r[0].style.background="yellow"),r[1]&&(r[1].style.background="yellow"),s.textContent="Medium",s.style.color="orange"):(r[0]&&(r[0].style.background="green"),r[1]&&(r[1].style.background="green"),r[2]&&(r[2].style.background="green"),s.textContent="Strong",s.style.color="green");const v=a.test(f)&&Object.values(h).every(Boolean);return t.style.border=v?"1px solid green":"1px solid red",void(v||"change"!==e.type||(t.value=""))}if("file"===t.type){n=!0;const e=t.getAttribute("data-kilvish-file")||"image",[r,...a]=e.split("_"),l=s[e]||s[r]||s.image,i=t.files;let d=1,c=1/0;if(a.length>=2&&(d=parseInt(a[0],10),c=parseInt(a[1],10)),i.length<d||i.length>c)return addErrorMessage(t,`Please select between ${d} and ${c} valid file(s).`),t.value="",t.style.border="1px solid red",!1;const u=o[e]||r.toUpperCase();for(const e of i)if(!l.includes(e.type))return addErrorMessage(t,`Invalid file type. Allowed types: ${u}.`),t.value="",t.style.border="1px solid red",!1}else n&&("keyup"===e.type&&(a.test(t.value)||("password"!==t.type&&addErrorMessage(t,"Invalid character entered!"),t.style.border="1px solid red")),"change"===e.type&&(a.test(t.value)?(t.style.border="",r(t)):(t.value="",addErrorMessage(t,"Invalid character or format!"),t.style.border="1px solid red")))}function addErrorMessage_working(e,t){if(!e.querySelector(".error-message")){const r=document.createElement("div");r.className="error-message",r.style.color="red",r.style.fontSize="12px",r.innerText=t,e.appendChild(r)}}function addErrorMessage_working2(e,t){const r=e.form?e.form:e.closest("form");if(!r)return;const{anchor:a,mode:n,key:s}=getErrorAnchor(e),o=getOrCreateErrorNode(r,a,n,s);o.textContent=t||"",o.classList.remove("is-hidden")}function addErrorMessage(e,t){const r=e.form?e.form:e.closest("form");if(!r)return;let a=null;if(e&&e.tagName&&/^(INPUT|SELECT|TEXTAREA)$/.test(e.tagName))a=e;else if(e&&e.querySelector){const t=e.querySelectorAll("input,select,textarea");a=t.length?t[t.length-1]:null}let n=e,s="beforeend",o="container";if(a){const e=a.nextElementSibling;"SELECT"===a.tagName&&e&&(e.classList.contains("select2")||e.classList.contains("select2-container"))?(n=e,s="afterend",o=a.name||a.id||"select"):a.parentElement&&a.parentElement.classList.contains("input-group")?(n=a.parentElement,s="afterend",o=a.name||a.id||"inputgroup"):(n=a,s="afterend",o=a.name||a.id||"field")}const l=`kil_err_${String(o).replace(/[^a-zA-Z0-9_\-]/g,"_")}`;let i=r.querySelector(`#${l}`);if(i||(i=document.createElement("div"),i.id=l,i.className="error-message is-hidden","beforeend"===s?n.insertAdjacentElement("beforeend",i):n.insertAdjacentElement("afterend",i)),i.textContent=t||"",i.classList.remove("is-hidden"),a)ensureStarVisibleFor(a);else{const t=e.querySelector("input[required],select[required],textarea[required]")||e.querySelector("input,select,textarea");t&&ensureStarVisibleFor(t)}}function getFieldAnchorForUI(e){return e.parentElement&&e.parentElement.classList.contains("input-group")?e.parentElement:e}function ensurePassUI(e){const t=getFieldAnchorForUI(e),r=e.name||e.id||"password",a=`kil_passui_${String(r).replace(/[^a-zA-Z0-9_-]/g,"_")}`;let n=t.parentNode.querySelector(`#${a}`);if(!n){n=document.createElement("div"),n.id=a,n.className="kil-passui";const e=document.createElement("div");e.className="password-strength";const r=document.createElement("div");r.className="bars";const s=document.createElement("div");s.className="bar";const o=document.createElement("div");o.className="bar";const l=document.createElement("div");l.className="bar",r.append(s,o,l);const i=document.createElement("span");i.className="label",i.textContent="Weak",i.style.fontSize="12px",e.append(r,i);const d=document.createElement("ul");d.className="password-validation",n.append(e,d),t.insertAdjacentElement("afterend",n)}const s=n.querySelectorAll(".bar"),o=n.querySelector(".password-strength .label"),l=n.querySelector(".password-validation");return{wrap:n,bars:s,label:o,rulesUl:l}}function getEyeAnchor(e){const t=e.closest(".input-group");if(t)return t.classList.add("kil-eye-rel"),e.classList.add("kil-eye-pad"),{anchor:t};if(!e.parentElement.classList.contains("kil-eye-wrap")){const t=document.createElement("span");t.className="kil-eye-wrap",e.parentNode.insertBefore(t,e),t.appendChild(e)}return e.classList.add("kil-eye-pad"),{anchor:e.parentElement}}function ensureEyeForPassword(e){if("1"===e.dataset.kileyeAttached)return;if(e.hasAttribute("data-kileye-false"))return;const{anchor:t}=getEyeAnchor(e);t.style.overflow="visible";let r=t.querySelector(".kil-eye-btn");r||(r=document.createElement("button"),r.type="button",r.className="kil-eye-btn",r.setAttribute("tabindex","-1"),r.setAttribute("aria-label","Show/Hide password"),r.innerHTML='<i class="fa fa-eye-slash" aria-hidden="true"></i>',t.appendChild(r));const a=e.getAttribute("data-kileye-color");a&&(r.style.color=a);const n=()=>r.querySelector("i");function s(){e.type="text",n()&&(n().classList.remove("fa-eye-slash"),n().classList.add("fa-eye"))}function o(){e.type="password",n()&&(n().classList.remove("fa-eye"),n().classList.add("fa-eye-slash"))}function l(){"password"===e.type?s():o()}const i=(e.getAttribute("data-kileye-show")||"hold").toLowerCase(),d=(e.getAttribute("data-kileye-initial")||"auto").toLowerCase();"fix"===i||"on"===d?s():"off"!==d&&"auto"!==d||o(),r.onmousedown=r.onmouseup=r.onmouseleave=r.onclick=null,r.ontouchstart=r.ontouchend=r.ontouchcancel=null,"toggle"===i||"fix"===i?(r.onclick=e=>{e.preventDefault(),l()},r.addEventListener("touchstart",(e=>{e.preventDefault(),l()}),{passive:!1})):(r.onmousedown=e=>{e.preventDefault(),s()},r.onmouseup=()=>o(),r.onmouseleave=()=>o(),r.onblur=()=>o(),r.addEventListener("touchstart",(e=>{e.preventDefault(),s()}),{passive:!1}),r.addEventListener("touchend",(()=>o())),r.addEventListener("touchcancel",(()=>o()))),e.addEventListener("blur",(()=>{"hold"===i&&o()})),e.dataset.kileyeAttached="1"}!function(){if(document.getElementById("kil-req-style"))return;const e=document.createElement("style");e.id="kil-req-style",e.textContent="\n .kil-required-star{ color:#d32f2f; margin-left:2px; }\n .error-message{ display:block; min-height:16px; margin-top:4px; font-size:12px; color:#d32f2f; line-height:1.25; opacity:1; transition:opacity .12s ease; }\n .error-message.is-hidden{ opacity:0; }\n ",document.head.appendChild(e)}(),document.addEventListener("DOMContentLoaded",(()=>{normalizeRequiredStars(),addAsteriskToRequiredFields()})),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll("form").forEach((e=>{const t=e.id;t?addRealTimeValidation(t):console.warn("Form without ID found. Skipping validation.")})),attachInputEvents(),addAsteriskToRequiredFields(),addValidateFormToSubmitButtons()})),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll("input[type='password']").forEach((e=>{if(e.hasAttribute("data-ignore-kilvish"))return;const{bars:t,label:r}=ensurePassUI(e),a=e.getAttribute("data-kilvish-password")||"12",[n]=a.split("_").map(Number);e.addEventListener("input",(e=>{const a=(e=>{let t=0;return e.length>=n&&(t+=2),/[A-Z]/.test(e)&&(t+=1),/[a-z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[\W_]/.test(e)&&(t+=1),(e=>{for(let t=0;t<e.length-3;t++){if(e.charCodeAt(t+1)===e.charCodeAt(t)+1&&e.charCodeAt(t+2)===e.charCodeAt(t)+2&&e.charCodeAt(t+3)===e.charCodeAt(t)+3)return!0;if(e.charCodeAt(t+1)===e.charCodeAt(t)-1&&e.charCodeAt(t+2)===e.charCodeAt(t)-2&&e.charCodeAt(t+3)===e.charCodeAt(t)-3)return!0}return!1})(e)&&(t-=2),Math.max(0,t)})(e.target.value);t.forEach((e=>e.style.background="lightgray")),a<=2?(t[0].style.background="red",r.textContent="Weak",r.style.color="red"):a<=4?(t[0].style.background="yellow",t[1].style.background="yellow",r.textContent="Medium",r.style.color="orange"):(t[0].style.background="green",t[1].style.background="green",t[2].style.background="green",r.textContent="Strong",r.style.color="green")}))}))})),function(){if(document.getElementById("kil-pass-style"))return;const e=document.createElement("style");e.id="kil-pass-style",e.textContent="\n .kil-passui { display:block; width:100%; margin-top:6px; }\n .kil-passui .password-strength { display:flex; align-items:center; gap:10px; }\n .kil-passui .password-strength .bars { display:flex; gap:4px; }\n .kil-passui .password-strength .bar { height:5px; width:30px; border-radius:3px; background:lightgray; }\n .kil-passui .password-validation { list-style:none; padding:0; margin:6px 0 0; }\n .kil-passui .password-validation li { font-size:12px; margin:2px 0; }\n ",document.head.appendChild(e)}(),function(){if(document.getElementById("kil-eye-style"))return;const e=document.createElement("style");e.id="kil-eye-style",e.textContent="\n .kil-eye-rel { position: relative !important; overflow: visible !important; }\n .kil-eye-wrap{ position:relative; display:block; }\n .kil-eye-btn{\n position:absolute; top:50%; right:10px; transform:translateY(-50%);\n display:inline-flex; align-items:center; justify-content:center;\n background:transparent; border:0; padding:0; margin:0;\n height:auto; width:auto; line-height:1; cursor:pointer; outline:none;\n z-index: 10; /* <-- stays above focused input */\n pointer-events: auto;\n }\n .kil-eye-btn i{ font-size:16px; }\n .kil-eye-pad { padding-right: 38px !important; }\n .kil-eye-btn { flex: 0 0 auto; }\n ",document.head.appendChild(e)}(),document.addEventListener("DOMContentLoaded",(()=>{document.querySelectorAll('input[type="password"]').forEach(ensureEyeForPassword)}));const _kilEyeObserver=new MutationObserver((e=>{for(const t of e)t.addedNodes&&t.addedNodes.forEach((e=>{e instanceof HTMLElement&&(e.matches&&e.matches('input[type="password"]')&&ensureEyeForPassword(e),e.querySelectorAll&&e.querySelectorAll('input[type="password"]').forEach(ensureEyeForPassword))}))}));_kilEyeObserver.observe(document.documentElement,{childList:!0,subtree:!0});
|