@colisweb/rescript-toolkit 5.10.6 → 5.11.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/package.json +1 -1
- package/src/form/ReSchema.res +20 -0
- package/src/form/ReSchemaI18n.res +2 -0
- package/src/form/Reform.res +1 -0
package/package.json
CHANGED
package/src/form/ReSchema.res
CHANGED
|
@@ -27,6 +27,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
27
27
|
module Validation = {
|
|
28
28
|
type rec t =
|
|
29
29
|
| Email({field: Lenses.field<string>, error: option<string>}): t
|
|
30
|
+
| Phone({field: Lenses.field<string>, error: option<string>}): t
|
|
30
31
|
| NoValidation({field: Lenses.field<'a>}): t
|
|
31
32
|
| StringNonEmpty({field: Lenses.field<string>, error: option<string>}): t
|
|
32
33
|
| StringRegExp({field: Lenses.field<string>, matches: string, error: option<string>}): t
|
|
@@ -81,6 +82,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
81
82
|
let false_ = (~error=?, field) => [False({field, error})]
|
|
82
83
|
|
|
83
84
|
let email = (~error=?, field) => [Email({field, error})]
|
|
85
|
+
let phone = (~error=?, field) => [Phone({field, error})]
|
|
84
86
|
|
|
85
87
|
let nonEmpty = (~error=?, field) => [StringNonEmpty({field, error})]
|
|
86
88
|
|
|
@@ -198,6 +200,22 @@ module Make = (Lenses: Lenses) => {
|
|
|
198
200
|
? Valid
|
|
199
201
|
: Error(error->Belt.Option.getWithDefault(i18n.email(~value))),
|
|
200
202
|
)
|
|
203
|
+
| Validation.Phone({field, error}) =>
|
|
204
|
+
let value = Lenses.get(values, field)
|
|
205
|
+
(
|
|
206
|
+
Field(field),
|
|
207
|
+
switch value {
|
|
208
|
+
| "" => Error(i18n.stringNonEmpty(~value=""))
|
|
209
|
+
| phone =>
|
|
210
|
+
if !(phone->Js.String2.startsWith("+33")) {
|
|
211
|
+
Error(error->Option.getWithDefault(i18n.phone))
|
|
212
|
+
} else if phone->Js.String2.sliceToEnd(~from=3)->Js.String2.length != 9 {
|
|
213
|
+
Error(error->Option.getWithDefault(i18n.phone))
|
|
214
|
+
} else {
|
|
215
|
+
Valid
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
)
|
|
201
219
|
| Validation.NoValidation({field}) => (Field(field), Valid)
|
|
202
220
|
| Validation.StringNonEmpty({field, error}) =>
|
|
203
221
|
let value = Lenses.get(values, field)
|
|
@@ -306,6 +324,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
306
324
|
| Validation.OptionNonEmpty({field}) => Field(field) == fieldName
|
|
307
325
|
| Validation.ArrayNonEmpty({field}) => Field(field) == fieldName
|
|
308
326
|
| Validation.CustomNestedSchema2({field}) => Field(field) == fieldName
|
|
327
|
+
| Validation.Phone({field}) => Field(field) == fieldName
|
|
309
328
|
}
|
|
310
329
|
)
|
|
311
330
|
|
|
@@ -313,6 +332,7 @@ module Make = (Lenses: Lenses) => {
|
|
|
313
332
|
validators->Belt.Array.keep(validator =>
|
|
314
333
|
switch validator {
|
|
315
334
|
| Validation.False({field}) => Field(field) == fieldName
|
|
335
|
+
| Validation.Phone({field}) => Field(field) == fieldName
|
|
316
336
|
| Validation.True({field}) => Field(field) == fieldName
|
|
317
337
|
| Validation.IntMin({field}) => Field(field) == fieldName
|
|
318
338
|
| Validation.IntMax({field}) => Field(field) == fieldName
|
|
@@ -10,6 +10,7 @@ type t = {
|
|
|
10
10
|
stringRegExp: (~value: string, ~pattern: string) => string,
|
|
11
11
|
stringMin: (~value: string, ~min: int) => string,
|
|
12
12
|
stringMax: (~value: string, ~max: int) => string,
|
|
13
|
+
phone: string,
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
let default = {
|
|
@@ -31,4 +32,5 @@ let default = {
|
|
|
31
32
|
`Le champ doit avoir au minimum ${min->Int.toString} caractères.`,
|
|
32
33
|
stringMax: (~value as _value, ~max) =>
|
|
33
34
|
`Le champ doit avoir au maximum ${max->Int.toString} caractères.`,
|
|
35
|
+
phone: "Format du numéro invalide. Ex : +33612345678",
|
|
34
36
|
}
|
package/src/form/Reform.res
CHANGED
|
@@ -111,6 +111,7 @@ module Make = (Config: Config) => {
|
|
|
111
111
|
| Validation.FloatMin({field}) => (Field(field), Pristine)
|
|
112
112
|
| Validation.FloatMax({field}) => (Field(field), Pristine)
|
|
113
113
|
| Validation.Email({field}) => (Field(field), Pristine)
|
|
114
|
+
| Validation.Phone({field}) => (Field(field), Pristine)
|
|
114
115
|
| Validation.NoValidation({field}) => (Field(field), Pristine)
|
|
115
116
|
| Validation.StringNonEmpty({field}) => (Field(field), Pristine)
|
|
116
117
|
| Validation.StringRegExp({field}) => (Field(field), Pristine)
|