From 5902e34b3436d2b3e6e43d819911a268c95d12d3 Mon Sep 17 00:00:00 2001 From: MrWindlike Date: Mon, 19 Feb 2024 11:09:42 +0800 Subject: [PATCH] feat(Validation): add the default values for the props and params --- packages/runtime/src/traits/core/Validation.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/runtime/src/traits/core/Validation.tsx b/packages/runtime/src/traits/core/Validation.tsx index 4491726b2..0f0af12d2 100644 --- a/packages/runtime/src/traits/core/Validation.tsx +++ b/packages/runtime/src/traits/core/Validation.tsx @@ -279,7 +279,7 @@ export default implementRuntimeTrait({ const resultMap = new Map(); return props => { - const { validators, componentId, subscribeMethods, mergeState } = props; + const { validators = [], componentId, subscribeMethods, mergeState } = props; const validatorMap = validators.reduce((result, validator) => { result[validator.name] = validator; @@ -287,7 +287,7 @@ export default implementRuntimeTrait({ }, {} as Record>); function setErrors({ - errorsMap, + errorsMap = {}, }: { errorsMap: Record[]>; }) { @@ -311,7 +311,7 @@ export default implementRuntimeTrait({ }); resultMap.set(componentId, validatedResult); } - function validateFields({ names }: { names: string[] }) { + function validateFields({ names = [] }: { names: string[] }) { const validatedResult = names .filter(name => validatorMap[name]) .map(name => { @@ -362,7 +362,7 @@ export default implementRuntimeTrait({ function validateAllFields() { validateFields({ names: validators.map(({ name }) => name) }); } - function clearErrors({ names }: { names: string[] }) { + function clearErrors({ names = [] }: { names: string[] }) { setErrors({ errorsMap: names.reduce((result: Record, name) => { result[name] = [];