Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

adding a prevalidation mode for usecases when you want validation on … #592

Merged
merged 3 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 2.6.4 (Unreleased)

- [#592](https://github.com/influxdata/clockface/pull/592): Add prevalidation mode for formValidationElement


### 2.6.3 (2021-3-15)

- [#582](https://github.com/influxdata/clockface/pull/582): Add icons
Expand Down
5 changes: 5 additions & 0 deletions src/Components/Form/Documentation/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const mockValidationFunc = (value: string): string | null => {
return 'Field cannot be empty'
}

if (value.length >= 21) {
return 'Must be 20 characters or less'
}

return null
}

Expand Down Expand Up @@ -360,6 +364,7 @@ formStories.add(
helpText={text('helpText', 'Help Text')}
required={boolean('required', true)}
validationFunc={mockValidationFunc}
prevalidate={boolean('prevalidate', false)}
>
{status => (
<Input
Expand Down
5 changes: 4 additions & 1 deletion src/Components/Form/FormValidationElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export interface FormValidationElementProps extends StandardFunctionProps {
required?: boolean
/** Useful for associating a label with an input */
htmlFor?: string
/** Pre-validation mode ( Validation happens ) */
prevalidate?: boolean
}

export type FormValidationElementRef = HTMLLabelElement
Expand All @@ -55,11 +57,12 @@ export const FormValidationElement = forwardRef<
className,
validationFunc,
onStatusChange,
prevalidate = false,
testID = 'form--validation-element',
},
ref
) => {
const shouldPerformValidation = useRef<boolean>(false)
const shouldPerformValidation = useRef<boolean>(prevalidate)

let errorMessage = null
let status = ComponentStatus.Default
Expand Down