From 4b712a35ea511e634010bf7f32bce6336376ed97 Mon Sep 17 00:00:00 2001 From: Medson Oliveira Date: Fri, 22 Nov 2019 15:45:34 -0300 Subject: [PATCH] feat(reschema): add method validateFields --- packages/reschema/src/ReSchema.re | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/reschema/src/ReSchema.re b/packages/reschema/src/ReSchema.re index 8fb7f581..f5c9f894 100644 --- a/packages/reschema/src/ReSchema.re +++ b/packages/reschema/src/ReSchema.re @@ -134,6 +134,19 @@ module Make = (Lenses: Lenses) => { ->Belt.Option.map(validator => validateField(~validator, ~values, ~i18n)); }; + let validateFields = (~fields, ~values, ~i18n, schema: Validation.schema) => { + let Validation.Schema(validators) = schema; + + Belt.Array.map(fields, field => + getFieldValidator(~validators, ~fieldName=field) + ) + ->Belt.Array.map(validator => + Belt.Option.map(validator, validator => + validateField(~validator, ~values, ~i18n) + ) + ); + }; + let validate = ( ~i18n=ReSchemaI18n.default,