@abgov/ui-components-common 1.2.1 → 1.2.2-alpha.2
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/index.cjs +1 -1
- package/index.js +86 -67
- package/lib/common.d.ts +1 -0
- package/lib/public-form-controller.d.ts +14 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var M=Object.defineProperty;var y=r=>{throw TypeError(r)};var S=(r,t,e)=>t in r?M(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var l=(r,t,e)=>S(r,typeof t!="symbol"?t+"":t,e),N=(r,t,e)=>t.has(r)||y("Cannot "+e);var g=(r,t,e)=>t.has(r)?y("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e);var V=(r,t,e)=>(N(r,t,"access private method"),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class E{constructor(t){l(this,"validators");this.validators=t||{}}add(t,...e){this.validators[t]=e}validate(t){const e={};return Object.entries(this.validators).forEach(([a,i])=>{const n=i.map(s=>s(t[a])).find(s=>!!s);n&&(e[a]=n)}),e}}function w(){return[c("Day is required"),m({min:1,max:31,minMsg:"Day must be between 1 and 31",maxMsg:"Day must be between 1 and 31"})]}function _(){return[c("Month is required"),m({min:0,max:11,minMsg:"Month must be between Jan and Dec",maxMsg:"Month must be between Jan and Dec"})]}function D(){const r=new Date().getFullYear();return[c("Year is required"),m({min:1900,max:r,minMsg:"Year must be greater than 1900",maxMsg:`Year must be less than ${r}`})]}function c(r){return t=>(r=r||"Required",typeof t=="number"&&!isNaN(t)||t?"":r)}function R(r){const t=new RegExp(/^\+?[\d-() ]{10,18}$/);return h(t,r||"Invalid phone number")}function $(r){const t=new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);return h(t,r||"Invalid email address")}function x(){return r=>{if(!r)return"";const t="121212121".split("").map(i=>parseInt(i)),e=r.replace(/\D/g,"");return e.length!==9?"SIN must contain 9 numbers":e.split("").map(i=>parseInt(i)).map((i,n)=>{const s=i*t[n];return s<10?s:`${s}`.split("").map(o=>parseInt(o)).reduce((o,u)=>o+u,0)}).reduce((i,n)=>i+n,0)%10===0?"":"Invalid SIN"}}function I(){return h(/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,"Invalid postal code")}function h(r,t){return e=>!e||e.match(r)?"":t}function C({invalidMsg:r,minMsg:t,maxMsg:e,min:a,max:i}={}){return n=>{let s=new Date(-1);return`${n||""}`.length===0?"":(typeof n=="string"&&(s=new Date(n)),typeof n=="number"&&(s=new Date(n)),n.toDateString&&(s=n),s.getDate()===-1?r||"Invalid date":a&&s<a?t||`Must be after ${a}`:i&&s>i?e||`Must be before ${i}`:"")}}function m({invalidTypeMsg:r,minMsg:t,maxMsg:e,min:a=-Number.MAX_VALUE,max:i=Number.MAX_VALUE}={}){return n=>{let s=Number.MAX_VALUE;return`${n??""}`.length===0?"":(typeof n=="string"&&(s=parseFloat(n)),typeof n=="number"&&(s=n),isNaN(s)?r||"Must be a numeric value":s>i?e||`Must be less than or equal to ${i}`:s<a?t||`Must be greater than or equal to ${a}`:"")}}function L({invalidTypeMsg:r,minMsg:t,maxMsg:e,min:a=-Number.MAX_VALUE,max:i=Number.MAX_VALUE}){return n=>`${n||""}`.length===0?"":typeof n!="string"?r||"Invalid type":n.length>i?e||`Must be less than ${i} characters`:n.length<a?t||`Must be greater than ${a} characters`:""}var f,T,A;class q{constructor(t){g(this,f);l(this,"state");l(this,"_formData");l(this,"_formRef");this.type=t}init(t){if(this._formRef){console.warn("init: form element has already been set");return}this._formRef=t.detail.el,this.state={uuid:crypto.randomUUID(),form:{},history:[],editting:"",status:"not-started"}}initList(t){this._formRef=t.detail.el,this.state=[]}initState(t,e){d(this._formRef,"external::init:state",t),typeof t=="string"?this.state=JSON.parse(t):Array.isArray(t)||(this.state=t),e&&setTimeout(e,200)}updateListState(t){const e=t.detail;Array.isArray(e.data)&&(this.state=e.data)}updateObjectState(t){var a,i;if(Array.isArray(this.state))return;const e=t.detail;e.type==="list"?this.state={...this.state,form:{...((a=this.state)==null?void 0:a.form)||{},[e.id]:e.data}}:this.state={...this.state,...e.data,form:{...((i=this.state)==null?void 0:i.form)||{},...e.data.form},history:e.data.history}}getStateList(){return this.state?Array.isArray(this.state)?this.state.length===0?[]:this.state.map(t=>Object.values(t.form).filter(e=>{var a;return((a=e==null?void 0:e.data)==null?void 0:a.type)==="details"}).map(e=>{var a;return e.data.type==="details"&&((a=e.data)==null?void 0:a.fieldsets)||{}}).reduce((e,a)=>{for(const[i,n]of Object.entries(a))e[i]=n.value;return e},{})):(console.warn("Utils:getStateList: unable to update the state of a non-multi form type",this.state),[]):[]}getStateValue(t,e){if(Array.isArray(this.state))return console.error("getStateValue: unable to update the state of a multi form type"),"";if(!this.state)return console.error("getStateValue: state has not yet been set"),"";const a=this.state.form[t].data;return a.type!=="details"?"":a.fieldsets[e].value}continueTo(t){if(!t){console.error("continueTo [name] is undefined");return}d(this._formRef,"external::continue",{next:t})}validate(t,e,a,i){var b;const{el:n,state:s,cancelled:o}=t.detail,u=(b=s==null?void 0:s[e])==null?void 0:b.value;if(window.scrollTo({top:0,behavior:"smooth"}),o)return[!0,u];for(const v of a){const p=v(u);if(V(this,f,A).call(this,n,e,p,i),p)return[!1,""]}return[!0,u]}validateGroup(t,e,a,i){let n=0;for(const s of e){const[o]=this.validate(t,s,i,{grouped:!0});o&&n++}return n>=a}edit(t){d(this._formRef,"external::alter:state",{index:t,operation:"edit"})}remove(t){d(this._formRef,"external::alter:state",{index:t,operation:"remove"})}clean(t){return t.history.reduce((e,a)=>(e[a]=t.form[a],e),{})}}f=new WeakSet,T=function(t){var e;Array.isArray(t.data)&&(Array.isArray(this.state)||(this.state={...this.state,form:{...((e=this.state)==null?void 0:e.form)||{},[t.id]:t.data}}))},A=function(t,e,a,i){t.dispatchEvent(new CustomEvent("msg",{composed:!0,detail:{action:"external::set:error",data:{name:e,msg:a,grouped:i==null?void 0:i.grouped}}}))};function U(r,t,e,a){if(!r){console.error("dispatch element is null");return}r.dispatchEvent(new CustomEvent(t,{composed:!0,bubbles:a==null?void 0:a.bubbles,detail:e}))}function d(r,t,e,a){if(!r){console.error("dispatch element is null");return}r.dispatchEvent(new CustomEvent("msg",{composed:!0,bubbles:a==null?void 0:a.bubbles,detail:{action:t,data:e}}))}exports.FormValidator=E;exports.PublicFormController=q;exports.SINValidator=x;exports.birthDayValidator=w;exports.birthMonthValidator=_;exports.birthYearValidator=D;exports.dateValidator=C;exports.dispatch=U;exports.emailValidator=$;exports.lengthValidator=L;exports.numericValidator=m;exports.phoneNumberValidator=R;exports.postalCodeValidator=I;exports.regexValidator=h;exports.relay=d;exports.requiredValidator=c;
|
package/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var M = Object.defineProperty;
|
|
2
|
+
var y = (r) => {
|
|
3
3
|
throw TypeError(r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
class
|
|
5
|
+
var S = (r, t, e) => t in r ? M(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
6
|
+
var l = (r, t, e) => S(r, typeof t != "symbol" ? t + "" : t, e), E = (r, t, e) => t.has(r) || y("Cannot " + e);
|
|
7
|
+
var g = (r, t, e) => t.has(r) ? y("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e);
|
|
8
|
+
var A = (r, t, e) => (E(r, t, "access private method"), e);
|
|
9
|
+
class _ {
|
|
10
10
|
constructor(t) {
|
|
11
|
-
|
|
11
|
+
l(this, "validators");
|
|
12
12
|
this.validators = t || {};
|
|
13
13
|
}
|
|
14
14
|
add(t, ...e) {
|
|
@@ -16,13 +16,13 @@ class N {
|
|
|
16
16
|
}
|
|
17
17
|
validate(t) {
|
|
18
18
|
const e = {};
|
|
19
|
-
return Object.entries(this.validators).forEach(([a,
|
|
20
|
-
const
|
|
21
|
-
|
|
19
|
+
return Object.entries(this.validators).forEach(([a, n]) => {
|
|
20
|
+
const i = n.map((s) => s(t[a])).find((s) => !!s);
|
|
21
|
+
i && (e[a] = i);
|
|
22
22
|
}), e;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function D() {
|
|
26
26
|
return [
|
|
27
27
|
c("Day is required"),
|
|
28
28
|
m({
|
|
@@ -33,7 +33,7 @@ function _() {
|
|
|
33
33
|
})
|
|
34
34
|
];
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function R() {
|
|
37
37
|
return [
|
|
38
38
|
c("Month is required"),
|
|
39
39
|
m({
|
|
@@ -44,7 +44,7 @@ function D() {
|
|
|
44
44
|
})
|
|
45
45
|
];
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function $() {
|
|
48
48
|
const r = (/* @__PURE__ */ new Date()).getFullYear();
|
|
49
49
|
return [
|
|
50
50
|
c("Year is required"),
|
|
@@ -59,27 +59,27 @@ function R() {
|
|
|
59
59
|
function c(r) {
|
|
60
60
|
return (t) => (r = r || "Required", typeof t == "number" && !isNaN(t) || t ? "" : r);
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function x(r) {
|
|
63
63
|
const t = new RegExp(/^\+?[\d-() ]{10,18}$/);
|
|
64
64
|
return h(t, r || "Invalid phone number");
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function I(r) {
|
|
67
67
|
const t = new RegExp(
|
|
68
68
|
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
69
69
|
);
|
|
70
70
|
return h(t, r || "Invalid email address");
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function L() {
|
|
73
73
|
return (r) => {
|
|
74
74
|
if (!r) return "";
|
|
75
|
-
const t = "121212121".split("").map((
|
|
76
|
-
return e.length !== 9 ? "SIN must contain 9 numbers" : e.split("").map((
|
|
77
|
-
const s =
|
|
78
|
-
return s < 10 ? s : `${s}`.split("").map((o) => parseInt(o)).reduce((o,
|
|
79
|
-
}).reduce((
|
|
75
|
+
const t = "121212121".split("").map((n) => parseInt(n)), e = r.replace(/\D/g, "");
|
|
76
|
+
return e.length !== 9 ? "SIN must contain 9 numbers" : e.split("").map((n) => parseInt(n)).map((n, i) => {
|
|
77
|
+
const s = n * t[i];
|
|
78
|
+
return s < 10 ? s : `${s}`.split("").map((o) => parseInt(o)).reduce((o, u) => o + u, 0);
|
|
79
|
+
}).reduce((n, i) => n + i, 0) % 10 === 0 ? "" : "Invalid SIN";
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function C() {
|
|
83
83
|
return h(
|
|
84
84
|
/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
|
85
85
|
"Invalid postal code"
|
|
@@ -88,16 +88,16 @@ function L() {
|
|
|
88
88
|
function h(r, t) {
|
|
89
89
|
return (e) => !e || e.match(r) ? "" : t;
|
|
90
90
|
}
|
|
91
|
-
function
|
|
91
|
+
function U({
|
|
92
92
|
invalidMsg: r,
|
|
93
93
|
minMsg: t,
|
|
94
94
|
maxMsg: e,
|
|
95
95
|
min: a,
|
|
96
|
-
max:
|
|
96
|
+
max: n
|
|
97
97
|
} = {}) {
|
|
98
|
-
return (
|
|
98
|
+
return (i) => {
|
|
99
99
|
let s = /* @__PURE__ */ new Date(-1);
|
|
100
|
-
return `${
|
|
100
|
+
return `${i || ""}`.length === 0 ? "" : (typeof i == "string" && (s = new Date(i)), typeof i == "number" && (s = new Date(i)), i.toDateString && (s = i), s.getDate() === -1 ? r || "Invalid date" : a && s < a ? t || `Must be after ${a}` : n && s > n ? e || `Must be before ${n}` : "");
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
function m({
|
|
@@ -105,29 +105,29 @@ function m({
|
|
|
105
105
|
minMsg: t,
|
|
106
106
|
maxMsg: e,
|
|
107
107
|
min: a = -Number.MAX_VALUE,
|
|
108
|
-
max:
|
|
108
|
+
max: n = Number.MAX_VALUE
|
|
109
109
|
} = {}) {
|
|
110
|
-
return (
|
|
110
|
+
return (i) => {
|
|
111
111
|
let s = Number.MAX_VALUE;
|
|
112
|
-
return `${
|
|
112
|
+
return `${i ?? ""}`.length === 0 ? "" : (typeof i == "string" && (s = parseFloat(i)), typeof i == "number" && (s = i), isNaN(s) ? r || "Must be a numeric value" : s > n ? e || `Must be less than or equal to ${n}` : s < a ? t || `Must be greater than or equal to ${a}` : "");
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
-
function
|
|
115
|
+
function q({
|
|
116
116
|
invalidTypeMsg: r,
|
|
117
117
|
minMsg: t,
|
|
118
118
|
maxMsg: e,
|
|
119
119
|
min: a = -Number.MAX_VALUE,
|
|
120
|
-
max:
|
|
120
|
+
max: n = Number.MAX_VALUE
|
|
121
121
|
}) {
|
|
122
|
-
return (
|
|
122
|
+
return (i) => `${i || ""}`.length === 0 ? "" : typeof i != "string" ? r || "Invalid type" : i.length > n ? e || `Must be less than ${n} characters` : i.length < a ? t || `Must be greater than ${a} characters` : "";
|
|
123
123
|
}
|
|
124
|
-
var f,
|
|
125
|
-
class
|
|
124
|
+
var f, w, v;
|
|
125
|
+
class T {
|
|
126
126
|
constructor(t) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
g(this, f);
|
|
128
|
+
l(this, "state");
|
|
129
|
+
l(this, "_formData");
|
|
130
|
+
l(this, "_formRef");
|
|
131
131
|
this.type = t;
|
|
132
132
|
}
|
|
133
133
|
// Obtain reference to the form element
|
|
@@ -156,7 +156,7 @@ class q {
|
|
|
156
156
|
Array.isArray(e.data) && (this.state = e.data);
|
|
157
157
|
}
|
|
158
158
|
updateObjectState(t) {
|
|
159
|
-
var a,
|
|
159
|
+
var a, n;
|
|
160
160
|
if (Array.isArray(this.state))
|
|
161
161
|
return;
|
|
162
162
|
const e = t.detail;
|
|
@@ -166,7 +166,7 @@ class q {
|
|
|
166
166
|
} : this.state = {
|
|
167
167
|
...this.state,
|
|
168
168
|
...e.data,
|
|
169
|
-
form: { ...((
|
|
169
|
+
form: { ...((n = this.state) == null ? void 0 : n.form) || {}, ...e.data.form },
|
|
170
170
|
history: e.data.history
|
|
171
171
|
};
|
|
172
172
|
}
|
|
@@ -179,8 +179,8 @@ class q {
|
|
|
179
179
|
return e.data.type === "details" && ((a = e.data) == null ? void 0 : a.fieldsets) || {};
|
|
180
180
|
}).reduce(
|
|
181
181
|
(e, a) => {
|
|
182
|
-
for (const [
|
|
183
|
-
e[
|
|
182
|
+
for (const [n, i] of Object.entries(a))
|
|
183
|
+
e[n] = i.value;
|
|
184
184
|
return e;
|
|
185
185
|
},
|
|
186
186
|
{}
|
|
@@ -226,17 +226,35 @@ class q {
|
|
|
226
226
|
d(this._formRef, "external::continue", { next: t });
|
|
227
227
|
}
|
|
228
228
|
// Public method to perform validation and send the appropriate messages to the form elements
|
|
229
|
-
validate(t, e, a) {
|
|
230
|
-
var
|
|
231
|
-
const { el: i, state:
|
|
232
|
-
if (window.scrollTo({ top: 0, behavior: "smooth" }),
|
|
233
|
-
return [!0,
|
|
229
|
+
validate(t, e, a, n) {
|
|
230
|
+
var b;
|
|
231
|
+
const { el: i, state: s, cancelled: o } = t.detail, u = (b = s == null ? void 0 : s[e]) == null ? void 0 : b.value;
|
|
232
|
+
if (window.scrollTo({ top: 0, behavior: "smooth" }), o)
|
|
233
|
+
return [!0, u];
|
|
234
234
|
for (const V of a) {
|
|
235
|
-
const
|
|
236
|
-
if (
|
|
235
|
+
const p = V(u);
|
|
236
|
+
if (A(this, f, v).call(this, i, e, p, n), p)
|
|
237
237
|
return [!1, ""];
|
|
238
238
|
}
|
|
239
|
-
return [!0,
|
|
239
|
+
return [!0, u];
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Validates a group of fields ensuring that at least `minPassCount` of the items within the group
|
|
243
|
+
* passes. This is useful in the scenario when n number fields are required out of n+m number of fields.
|
|
244
|
+
*
|
|
245
|
+
* @param {string[]} fields - An array of field names to be validated.
|
|
246
|
+
* @param {Event} e - The event object associated with the validation trigger.
|
|
247
|
+
* @param minPassCount - The minimum number of fields that are required to pass to return true.
|
|
248
|
+
* @param {FieldValidator[]} validators - An array of validator functions to apply to the fields.
|
|
249
|
+
* @return {boolean} - Returns true if at least one field in the group is valid; otherwise, false.
|
|
250
|
+
*/
|
|
251
|
+
validateGroup(t, e, a, n) {
|
|
252
|
+
let i = 0;
|
|
253
|
+
for (const s of e) {
|
|
254
|
+
const [o] = this.validate(t, s, n, { grouped: !0 });
|
|
255
|
+
o && i++;
|
|
256
|
+
}
|
|
257
|
+
return i >= a;
|
|
240
258
|
}
|
|
241
259
|
edit(t) {
|
|
242
260
|
d(this._formRef, "external::alter:state", { index: t, operation: "edit" });
|
|
@@ -249,7 +267,7 @@ class q {
|
|
|
249
267
|
return t.history.reduce((e, a) => (e[a] = t.form[a], e), {});
|
|
250
268
|
}
|
|
251
269
|
}
|
|
252
|
-
f = new WeakSet(),
|
|
270
|
+
f = new WeakSet(), w = function(t) {
|
|
253
271
|
var e;
|
|
254
272
|
Array.isArray(t.data) && (Array.isArray(this.state) || (this.state = {
|
|
255
273
|
...this.state,
|
|
@@ -259,7 +277,7 @@ f = new WeakSet(), E = function(t) {
|
|
|
259
277
|
}
|
|
260
278
|
}));
|
|
261
279
|
}, // Private method to dispatch the error message to the form element
|
|
262
|
-
|
|
280
|
+
v = function(t, e, a, n) {
|
|
263
281
|
t.dispatchEvent(
|
|
264
282
|
new CustomEvent("msg", {
|
|
265
283
|
composed: !0,
|
|
@@ -267,13 +285,14 @@ A = function(t, e, a) {
|
|
|
267
285
|
action: "external::set:error",
|
|
268
286
|
data: {
|
|
269
287
|
name: e,
|
|
270
|
-
msg: a
|
|
288
|
+
msg: a,
|
|
289
|
+
grouped: n == null ? void 0 : n.grouped
|
|
271
290
|
}
|
|
272
291
|
}
|
|
273
292
|
})
|
|
274
293
|
);
|
|
275
294
|
};
|
|
276
|
-
function
|
|
295
|
+
function Y(r, t, e, a) {
|
|
277
296
|
if (!r) {
|
|
278
297
|
console.error("dispatch element is null");
|
|
279
298
|
return;
|
|
@@ -303,19 +322,19 @@ function d(r, t, e, a) {
|
|
|
303
322
|
);
|
|
304
323
|
}
|
|
305
324
|
export {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
325
|
+
_ as FormValidator,
|
|
326
|
+
T as PublicFormController,
|
|
327
|
+
L as SINValidator,
|
|
328
|
+
D as birthDayValidator,
|
|
329
|
+
R as birthMonthValidator,
|
|
330
|
+
$ as birthYearValidator,
|
|
331
|
+
U as dateValidator,
|
|
332
|
+
Y as dispatch,
|
|
333
|
+
I as emailValidator,
|
|
334
|
+
q as lengthValidator,
|
|
316
335
|
m as numericValidator,
|
|
317
|
-
|
|
318
|
-
|
|
336
|
+
x as phoneNumberValidator,
|
|
337
|
+
C as postalCodeValidator,
|
|
319
338
|
h as regexValidator,
|
|
320
339
|
d as relay,
|
|
321
340
|
c as requiredValidator
|
package/lib/common.d.ts
CHANGED
|
@@ -240,6 +240,7 @@ export type GoabTextTextElement = "span" | "div" | "p";
|
|
|
240
240
|
export type GoabTextHeadingSize = "heading-xl" | "heading-l" | "heading-m" | "heading-s" | "heading-xs";
|
|
241
241
|
export type GoabTextBodySize = "body-l" | "body-m" | "body-s" | "body-xs";
|
|
242
242
|
export type GoabTextSize = GoabTextHeadingSize | GoabTextBodySize;
|
|
243
|
+
export type GoabTextColor = "primary" | "secondary";
|
|
243
244
|
export type GoabFielsetOnContinueDetail = {
|
|
244
245
|
el: HTMLElement;
|
|
245
246
|
state: Record<string, string>;
|
|
@@ -38,7 +38,20 @@ export declare class PublicFormController<T> {
|
|
|
38
38
|
getStateList(): Record<string, string>[];
|
|
39
39
|
getStateValue(group: string, key: string): string;
|
|
40
40
|
continueTo(next: T | undefined): void;
|
|
41
|
-
validate(
|
|
41
|
+
validate(e: Event, field: string, validators: FieldValidator[], options?: {
|
|
42
|
+
grouped: boolean;
|
|
43
|
+
}): [boolean, string];
|
|
44
|
+
/**
|
|
45
|
+
* Validates a group of fields ensuring that at least `minPassCount` of the items within the group
|
|
46
|
+
* passes. This is useful in the scenario when n number fields are required out of n+m number of fields.
|
|
47
|
+
*
|
|
48
|
+
* @param {string[]} fields - An array of field names to be validated.
|
|
49
|
+
* @param {Event} e - The event object associated with the validation trigger.
|
|
50
|
+
* @param minPassCount - The minimum number of fields that are required to pass to return true.
|
|
51
|
+
* @param {FieldValidator[]} validators - An array of validator functions to apply to the fields.
|
|
52
|
+
* @return {boolean} - Returns true if at least one field in the group is valid; otherwise, false.
|
|
53
|
+
*/
|
|
54
|
+
validateGroup(e: Event, fields: string[], minPassCount: number, validators: FieldValidator[]): boolean;
|
|
42
55
|
edit(index: number): void;
|
|
43
56
|
remove(index: number): void;
|
|
44
57
|
clean(data: AppState<T>): Record<string, unknown>;
|