From b26f52d00a9461a2387c586701443d54896e9133 Mon Sep 17 00:00:00 2001 From: Pedro Guerrato Date: Wed, 16 Feb 2022 15:25:51 -0300 Subject: [PATCH] Include onFeedback method to show the validation responses --- src/lib/components/inputs/basic/password/Password.tsx | 1 + src/lib/components/inputs/basic/search/Search.tsx | 1 + src/lib/components/inputs/basic/shared/types.ts | 3 ++- src/lib/components/inputs/basic/text/Text.tsx | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/components/inputs/basic/password/Password.tsx b/src/lib/components/inputs/basic/password/Password.tsx index 5e545544..cad3fe8d 100644 --- a/src/lib/components/inputs/basic/password/Password.tsx +++ b/src/lib/components/inputs/basic/password/Password.tsx @@ -25,6 +25,7 @@ export const Password = (props: InputProps) => { useEffect(() => { props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) + props.onFeedback?.call(null, validationResponse) }, [validationResponse]) return ( diff --git a/src/lib/components/inputs/basic/search/Search.tsx b/src/lib/components/inputs/basic/search/Search.tsx index da986997..37258f93 100644 --- a/src/lib/components/inputs/basic/search/Search.tsx +++ b/src/lib/components/inputs/basic/search/Search.tsx @@ -22,6 +22,7 @@ export const Search = (props: InputProps) => { useEffect(() => { props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) + props.onFeedback?.call(null, validationResponse) }, [validationResponse]) return ( diff --git a/src/lib/components/inputs/basic/shared/types.ts b/src/lib/components/inputs/basic/shared/types.ts index fe4f8a88..99d8d7f3 100644 --- a/src/lib/components/inputs/basic/shared/types.ts +++ b/src/lib/components/inputs/basic/shared/types.ts @@ -22,6 +22,7 @@ export type InputProps = { criteria?: InputValidation | InputValidation[] onChange?: ChangeEventHandler onValidate?: (isValid: boolean) => void + onFeedback?: (validationResponse: InputCriteriaResponse | InputCriteriaResponse[]) => void inputStyles?: SharedProps readOnly?: boolean autoComplete?: AutocompleteValues @@ -80,7 +81,7 @@ export const criteriaRule = ( } export const getResultantValidationResponse = ( - validationResponse: InputCriteriaResponse | InputCriteriaResponse[] | undefined + validationResponse?: InputCriteriaResponse | InputCriteriaResponse[] ) => { if (!validationResponse) { return false diff --git a/src/lib/components/inputs/basic/text/Text.tsx b/src/lib/components/inputs/basic/text/Text.tsx index 281b2ee6..9bd49995 100644 --- a/src/lib/components/inputs/basic/text/Text.tsx +++ b/src/lib/components/inputs/basic/text/Text.tsx @@ -17,6 +17,7 @@ export const Text = (props: InputProps) => { useEffect(() => { props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) + props.onFeedback?.call(null, validationResponse) }, [validationResponse]) return (