Skip to content

Commit

Permalink
feat(forms/NewFormikDateField): add option to set field touched direc…
Browse files Browse the repository at this point in the history
…tly on change
  • Loading branch information
sjschlapbach committed Aug 12, 2024
1 parent cc29395 commit bb4072c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/forms/NewFormikDateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface NewFormikDateFieldProps {
tooltip?: string | React.ReactNode
required?: boolean
hideError?: boolean
touchedOnChange?: boolean
disabled?: boolean
className?: {
root?: string
Expand All @@ -44,6 +45,7 @@ export interface NewFormikDateFieldProps {
* @param tooltip - The optional tooltip is shown on hover next to the label.
* @param required - Indicate whether the field is required or not.
* @param hideError - Hide the error message below this component as is might be more appropriate to show it somewhere else.
* @param touchedOnChange - Indicate whether the field should be marked as touched on change.
* @param disabled - Disable the field.
* @param className - The optional className object allows you to override the default styling.
* @returns Date field component with Formik state management.
Expand All @@ -58,6 +60,7 @@ export function NewFormikDateField({
tooltip,
required = false,
hideError = false,
touchedOnChange = false,
disabled = false,
className,
...props
Expand Down Expand Up @@ -101,6 +104,10 @@ export function NewFormikDateField({
onChange={(e) => {
if (e.target['validity'].valid) {
helpers.setValue(e.target['value'])

if (touchedOnChange) {
helpers.setTouched(true)
}
}
}}
onBlur={() => helpers.setTouched(true)}
Expand Down

0 comments on commit bb4072c

Please sign in to comment.