@verbb/formie-browser 1.0.3 → 1.0.4
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/CHANGELOG.md +8 -0
- package/dist/chunks/{address-finder-BjMuEiwF.js → address-finder-BU4roxT6.js} +2 -2
- package/dist/chunks/{bpoint-KudsBCo2.js → bpoint-uNg5j6rt.js} +1 -1
- package/dist/chunks/{calculations-DlGSkQ3W.js → calculations-C9t6Zop9.js} +2 -2
- package/dist/chunks/{captcha-eu-CterYFok.js → captcha-eu-BAPzHNts.js} +2 -2
- package/dist/chunks/{checkbox-radio-CBvgk3hR.js → checkbox-radio-CHeLNVIK.js} +39 -34
- package/dist/chunks/{conditions-DYy1-Hwt.js → conditions-DKxVCsjD.js} +2 -2
- package/dist/chunks/{date-picker-BlD--zfe.js → date-picker-B3iQ797Z.js} +2 -2
- package/dist/chunks/{eway-qwc-B5Us.js → eway-DCielIML.js} +2 -2
- package/dist/chunks/{file-upload-CIgHrXfp.js → file-upload-DP2TOUYV.js} +34 -34
- package/dist/chunks/{friendly-captcha-v1-EDFac33c.js → friendly-captcha-v1-DdlcGiFY.js} +1 -1
- package/dist/chunks/{friendly-captcha-v2-BDpSvFGR.js → friendly-captcha-v2-76w-YnFm.js} +1 -1
- package/dist/chunks/{go-cardless-DuDMVsnz.js → go-cardless-rwCkzbNK.js} +1 -1
- package/dist/chunks/{google-address-Bmjp01pH.js → google-address-BD8IZ86V.js} +2 -2
- package/dist/chunks/{hcaptcha-BTQ6An6g.js → hcaptcha-BNNTL6uf.js} +2 -2
- package/dist/chunks/{hidden-DbPdOxKb.js → hidden-CW6Rcf1N.js} +1 -1
- package/dist/chunks/{index-BcqwpPNE.js → index-D6npYxvr.js} +790 -681
- package/dist/chunks/{loqate-BdNGv93o.js → loqate-B-ZNS65B.js} +2 -2
- package/dist/chunks/{mollie-DFOjTuGX.js → mollie-BDAZ-1X4.js} +1 -1
- package/dist/chunks/{moneris-BbFfl-EL.js → moneris-B1b0uEtY.js} +1 -1
- package/dist/chunks/{opayo-CmgYa9ya.js → opayo-CC5hraHo.js} +2 -2
- package/dist/chunks/{paddle-BUi7w1_o.js → paddle-B4GmrDsq.js} +2 -2
- package/dist/chunks/{paypal-A-ePfh6k.js → paypal-BFS6XsIS.js} +2 -2
- package/dist/chunks/{payway-BqFCbhyo.js → payway-DekoJead.js} +2 -2
- package/dist/chunks/{phone-country-DPMiqk4L.js → phone-country-Cm5YUeXI.js} +2 -2
- package/dist/chunks/{place-kit-CX7tamAg.js → place-kit-DizZWV_e.js} +1 -1
- package/dist/chunks/{recaptcha-enterprise-DxF6cW95.js → recaptcha-enterprise-BbOvO7JZ.js} +2 -2
- package/dist/chunks/{recaptcha-shared-DhGcbiaq.js → recaptcha-shared-Dwg1eVFS.js} +2 -2
- package/dist/chunks/{recaptcha-v2-checkbox-R9EfbZ4k.js → recaptcha-v2-checkbox-SY3ti5iQ.js} +2 -2
- package/dist/chunks/{recaptcha-v2-invisible-DV9hswAp.js → recaptcha-v2-invisible-DSmQnn6c.js} +2 -2
- package/dist/chunks/{recaptcha-v3-V0xc-Edh.js → recaptcha-v3-DNh7YCnR.js} +2 -2
- package/dist/chunks/{repeater-DKUT6TGI.js → repeater-DM0vuFNQ.js} +2 -2
- package/dist/chunks/{rich-text-SH7KiaKH.js → rich-text-C8aGYp70.js} +1 -1
- package/dist/chunks/{scripts-D9N2d5rN.js → scripts-CKTFtxPO.js} +1 -1
- package/dist/chunks/{shared-BmntPmnW.js → shared--BU5CFoL.js} +1 -1
- package/dist/chunks/{signature-BA3tQsGT.js → signature-pFhZfH7d.js} +1 -1
- package/dist/chunks/{snaptcha-DV7p6J9k.js → snaptcha-VuOUOaLj.js} +1 -1
- package/dist/chunks/{square-Bs-ndqYK.js → square-BR9pvToy.js} +4 -4
- package/dist/chunks/{stripe-DkZAHxtn.js → stripe-OHUwoV9g.js} +2 -2
- package/dist/chunks/{summary-Dq2i9TQk.js → summary-Da7Ktg3N.js} +2 -2
- package/dist/chunks/{table-Cu4WfVcw.js → table-C0PmR9bI.js} +2 -2
- package/dist/chunks/text-limit-mLEwZDIa.js +144 -0
- package/dist/chunks/{turnstile-CId90tRr.js → turnstile-9tM7q_LK.js} +2 -2
- package/dist/index.js +9 -9
- package/dist/js/core/field-error-container.d.ts +4 -0
- package/dist/js/core/field-error-container.d.ts.map +1 -0
- package/dist/js/core/submit-result-state.d.ts.map +1 -1
- package/dist/js/core/submit-result-ui.d.ts.map +1 -1
- package/dist/js/modules/fields/checkbox-radio.d.ts.map +1 -1
- package/dist/js/modules/fields/file-upload.d.ts.map +1 -1
- package/dist/js/modules/fields/text-limit.d.ts.map +1 -1
- package/dist/js/utils/i18n.d.ts.map +1 -1
- package/dist/js/validation/rules/email.d.ts.map +1 -1
- package/dist/js/validation/rules/number.d.ts.map +1 -1
- package/dist/js/validation/validator.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/js/core/field-error-container.ts +39 -0
- package/src/js/core/submit-result-state.ts +12 -2
- package/src/js/core/submit-result-ui.ts +3 -9
- package/src/js/modules/fields/checkbox-radio.ts +21 -15
- package/src/js/modules/fields/file-upload.ts +12 -9
- package/src/js/modules/fields/text-limit.ts +87 -22
- package/src/js/utils/i18n.ts +184 -5
- package/src/js/validation/rules/email.ts +3 -2
- package/src/js/validation/rules/match.ts +2 -2
- package/src/js/validation/rules/minmax.ts +4 -4
- package/src/js/validation/rules/number.ts +9 -5
- package/src/js/validation/rules/pattern.ts +4 -4
- package/src/js/validation/rules/required.ts +1 -1
- package/src/js/validation/rules/url.ts +1 -1
- package/src/js/validation/validator.ts +7 -7
- package/dist/chunks/text-limit-2ycmB-Ae.js +0 -135
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ensureFieldErrorContainer } from '#core/field-error-container';
|
|
1
2
|
import { syncPageTabErrors } from '#core/page-tab-errors';
|
|
2
3
|
import rules from '#validation/rules';
|
|
3
4
|
import type {
|
|
@@ -320,12 +321,11 @@ export class FormieValidator {
|
|
|
320
321
|
let errorMessages = fieldContainer.querySelector('[data-formie-field-errors]') as HTMLElement | null;
|
|
321
322
|
|
|
322
323
|
if (!errorMessages) {
|
|
323
|
-
errorMessages =
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
fieldContainer.appendChild(errorMessages);
|
|
324
|
+
errorMessages = ensureFieldErrorContainer(fieldContainer, (container) => {
|
|
325
|
+
if (this.config.messagesClass.length) {
|
|
326
|
+
container.classList.add(...this.config.messagesClass);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
if (this.config.messagesClass.length) {
|
|
@@ -402,7 +402,7 @@ export class FormieValidator {
|
|
|
402
402
|
|
|
403
403
|
getErrorMessage(input: ValidationInput, validatorName: string, validator: ValidatorDefinition, opts: ValidationContext): string {
|
|
404
404
|
const errorMessage = typeof validator.errorMessage === 'function' ? validator.errorMessage(opts) : validator.errorMessage;
|
|
405
|
-
return errorMessage ?? t('{
|
|
405
|
+
return errorMessage ?? t('{label} is invalid.', { label: opts.label });
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
getErrors(): ValidationError[] {
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { z as u } from "./index-BEsfee-D.js";
|
|
2
|
-
import { f as L, r as w, a as T } from "./shared-BmntPmnW.js";
|
|
3
|
-
import { e as v } from "./styles-C3aqgtek.js";
|
|
4
|
-
const C = "@layer formie-theme{.formie-limit-number{font-weight:var(--formie-font-weight-semibold);color:var(--formie-color-text)}.formie-limit-number-error{color:var(--formie-color-danger)}}", c = "input[data-formie-single-line-text-input], textarea[data-formie-multi-line-text-input]", E = [
|
|
5
|
-
"textMinCharacterLimit",
|
|
6
|
-
"textMaxCharacterLimit",
|
|
7
|
-
"textMinWordLimit",
|
|
8
|
-
"textMaxWordLimit"
|
|
9
|
-
], A = "text-limit", f = "data-formie-text-limit-allow-overtype", n = /* @__PURE__ */ new WeakMap();
|
|
10
|
-
v("text-limit", [C]);
|
|
11
|
-
function d(t) {
|
|
12
|
-
return t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement;
|
|
13
|
-
}
|
|
14
|
-
function m(t, i) {
|
|
15
|
-
return parseInt(t.getAttribute(i) || "", 10) || 0;
|
|
16
|
-
}
|
|
17
|
-
function M(t) {
|
|
18
|
-
return t.hasAttribute("data-formie-min-chars") || t.hasAttribute("data-formie-max-chars") || t.hasAttribute("data-formie-min-words") || t.hasAttribute("data-formie-max-words");
|
|
19
|
-
}
|
|
20
|
-
function y(t) {
|
|
21
|
-
return t.hasAttribute("data-formie-max-chars") || t.hasAttribute("data-formie-max-words");
|
|
22
|
-
}
|
|
23
|
-
function h(t) {
|
|
24
|
-
return t.hasAttribute(f);
|
|
25
|
-
}
|
|
26
|
-
function x(t) {
|
|
27
|
-
return t.value === "";
|
|
28
|
-
}
|
|
29
|
-
function V(t) {
|
|
30
|
-
w(t, A, (i) => {
|
|
31
|
-
i.addValidator("textMinCharacterLimit", ({ input: e }) => {
|
|
32
|
-
if (!d(e))
|
|
33
|
-
return !0;
|
|
34
|
-
const r = m(e, "data-formie-min-chars");
|
|
35
|
-
return !r || x(e) ? !0 : u(e.value).graphemeCount >= r;
|
|
36
|
-
}, ({ label: e, input: r, t: a }) => a("{attribute} must be no less than {min} characters.", {
|
|
37
|
-
attribute: e,
|
|
38
|
-
min: r.getAttribute("data-formie-min-chars") || ""
|
|
39
|
-
})), i.addValidator("textMaxCharacterLimit", ({ input: e }) => {
|
|
40
|
-
if (!d(e) || h(e))
|
|
41
|
-
return !0;
|
|
42
|
-
const r = m(e, "data-formie-max-chars");
|
|
43
|
-
return !r || x(e) ? !0 : u(e.value).graphemeCount <= r;
|
|
44
|
-
}, ({ label: e, input: r, t: a }) => a("{attribute} must be no greater than {max} characters.", {
|
|
45
|
-
attribute: e,
|
|
46
|
-
max: r.getAttribute("data-formie-max-chars") || ""
|
|
47
|
-
})), i.addValidator("textMinWordLimit", ({ input: e }) => {
|
|
48
|
-
if (!d(e))
|
|
49
|
-
return !0;
|
|
50
|
-
const r = m(e, "data-formie-min-words");
|
|
51
|
-
return !r || e.value.trim() === "" ? !0 : u(e.value).wordCount >= r;
|
|
52
|
-
}, ({ label: e, input: r, t: a }) => a("{attribute} must be no less than {min} words.", {
|
|
53
|
-
attribute: e,
|
|
54
|
-
min: r.getAttribute("data-formie-min-words") || ""
|
|
55
|
-
})), i.addValidator("textMaxWordLimit", ({ input: e }) => {
|
|
56
|
-
if (!d(e) || h(e))
|
|
57
|
-
return !0;
|
|
58
|
-
const r = m(e, "data-formie-max-words");
|
|
59
|
-
return !r || e.value.trim() === "" ? !0 : u(e.value).wordCount <= r;
|
|
60
|
-
}, ({ label: e, input: r, t: a }) => a("{attribute} must be no greater than {max} words.", {
|
|
61
|
-
attribute: e,
|
|
62
|
-
max: r.getAttribute("data-formie-max-words") || ""
|
|
63
|
-
}));
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function I(t) {
|
|
67
|
-
T(t, A, E);
|
|
68
|
-
}
|
|
69
|
-
function O(t) {
|
|
70
|
-
if (n.has(t))
|
|
71
|
-
return n.get(t) || null;
|
|
72
|
-
const i = t.closest("[data-formie-field-handle]");
|
|
73
|
-
if (!i)
|
|
74
|
-
return n.set(t, null), null;
|
|
75
|
-
const e = i.querySelector("[data-formie-limit-text]");
|
|
76
|
-
if (e)
|
|
77
|
-
return n.set(t, e), e;
|
|
78
|
-
const r = i.querySelector("[data-formie-field-control]"), a = document.createElement("div");
|
|
79
|
-
return a.className = "formie-field-limit formie-limit-text", a.setAttribute("data-formie-field-limit", "true"), a.setAttribute("data-formie-limit-text", "true"), r?.parentElement ? (r.insertAdjacentElement("afterend", a), n.set(t, a), a) : (i.appendChild(a), n.set(t, a), a);
|
|
80
|
-
}
|
|
81
|
-
function b(t, i, e) {
|
|
82
|
-
const r = document.createElement("span");
|
|
83
|
-
r.className = i < 0 ? "formie-limit-number formie-limit-number-error" : "formie-limit-number", r.textContent = String(i), t.replaceChildren(
|
|
84
|
-
r,
|
|
85
|
-
document.createTextNode(` ${Math.abs(i) === 1 ? e : `${e}s`} left`)
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
function g(t) {
|
|
89
|
-
const i = m(t, "data-formie-max-chars"), e = m(t, "data-formie-max-words"), r = O(t);
|
|
90
|
-
if (!r)
|
|
91
|
-
return;
|
|
92
|
-
const a = u(t.value);
|
|
93
|
-
if (i > 0) {
|
|
94
|
-
const s = i - a.graphemeCount;
|
|
95
|
-
b(r, s, "character");
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (e > 0) {
|
|
99
|
-
const s = e - a.wordCount;
|
|
100
|
-
b(r, s, "word");
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const _ = {
|
|
104
|
-
id: "text-limit",
|
|
105
|
-
kind: "field",
|
|
106
|
-
match: (t) => !!t.target.querySelector(c),
|
|
107
|
-
setup: async (t) => {
|
|
108
|
-
const i = t.options || {}, e = L(t), r = Array.from((e || t.target).querySelectorAll(c)).filter((o) => (o instanceof HTMLInputElement || o instanceof HTMLTextAreaElement) && M(o)), a = r.filter((o) => y(o));
|
|
109
|
-
i.allowOvertype && r.forEach((o) => {
|
|
110
|
-
o.setAttribute(f, "true");
|
|
111
|
-
}), V(t.form);
|
|
112
|
-
const s = a.map((o) => {
|
|
113
|
-
const l = () => {
|
|
114
|
-
g(o);
|
|
115
|
-
};
|
|
116
|
-
return o.addEventListener("input", l), o.addEventListener("change", l), g(o), () => {
|
|
117
|
-
o.removeEventListener("input", l), o.removeEventListener("change", l);
|
|
118
|
-
};
|
|
119
|
-
});
|
|
120
|
-
return await t.emit("formie:module:text-limit:init", {
|
|
121
|
-
count: r.length
|
|
122
|
-
}), {
|
|
123
|
-
destroy: () => {
|
|
124
|
-
s.forEach((o) => {
|
|
125
|
-
o();
|
|
126
|
-
}), i.allowOvertype && r.forEach((o) => {
|
|
127
|
-
o.removeAttribute(f);
|
|
128
|
-
}), I(t.form), t.emit("formie:module:text-limit:destroy", {});
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
export {
|
|
134
|
-
_ as textLimitModule
|
|
135
|
-
};
|