@colisweb/rescript-toolkit 5.26.1 → 5.26.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/package.json +1 -1
- package/src/form/ReSchema.res +14 -6
package/package.json
CHANGED
package/src/form/ReSchema.res
CHANGED
|
@@ -71,7 +71,11 @@ module Make = (Lenses: Lenses) => {
|
|
|
71
71
|
}): t
|
|
72
72
|
| True({field: Lenses.field<bool>, error: option<string>}): t
|
|
73
73
|
| False({field: Lenses.field<bool>, error: option<string>}): t
|
|
74
|
-
| OptionNonEmpty({
|
|
74
|
+
| OptionNonEmpty({
|
|
75
|
+
field: Lenses.field<option<'a>>,
|
|
76
|
+
optionalPredicate?: Lenses.state => bool,
|
|
77
|
+
error: option<string>,
|
|
78
|
+
}): t
|
|
75
79
|
| ArrayNonEmpty({field: Lenses.field<array<'a>>, error: option<string>}): t
|
|
76
80
|
|
|
77
81
|
type schema = array<t>
|
|
@@ -96,7 +100,9 @@ module Make = (Lenses: Lenses) => {
|
|
|
96
100
|
[CustomNestedSchema2({field, predicate})]
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
let optionNonEmpty = (~error=?, field) => [
|
|
103
|
+
let optionNonEmpty = (~error=?, ~optionalPredicate=?, field) => [
|
|
104
|
+
OptionNonEmpty({field, ?optionalPredicate, error}),
|
|
105
|
+
]
|
|
100
106
|
|
|
101
107
|
let arrayNonEmpty = (~error=?, field) => [ArrayNonEmpty({field, error})]
|
|
102
108
|
|
|
@@ -359,14 +365,16 @@ module Make = (Lenses: Lenses) => {
|
|
|
359
365
|
|
|
360
366
|
(Field(field), NestedErrors2(results))
|
|
361
367
|
}
|
|
362
|
-
| Validation.OptionNonEmpty({field, error}) => {
|
|
368
|
+
| Validation.OptionNonEmpty({field, error} as props) => {
|
|
363
369
|
let value = Lenses.get(values, field)
|
|
364
370
|
|
|
365
371
|
(
|
|
366
372
|
Field(field),
|
|
367
|
-
value
|
|
368
|
-
|
|
369
|
-
|
|
373
|
+
switch value {
|
|
374
|
+
| _ if props.optionalPredicate->Option.mapWithDefault(false, fn => fn(values)) => Valid
|
|
375
|
+
| None => Error(error->Belt.Option.getWithDefault(i18n.stringNonEmpty(~value="")))
|
|
376
|
+
| Some(_) => Valid
|
|
377
|
+
},
|
|
370
378
|
)
|
|
371
379
|
}
|
|
372
380
|
| Validation.ArrayNonEmpty({field, error}) => {
|