Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: correct date validation for disabled fields #7240

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion frontend/src/templates/Field/Date/DateField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useMemo } from 'react'
import { Controller, useFormContext } from 'react-hook-form'
import { useParams } from 'react-router-dom'

import { DATE_DISPLAY_FORMAT, DATE_PARSE_FORMAT } from '~shared/constants/dates'
import { FormColorTheme } from '~shared/types'
Expand Down Expand Up @@ -32,11 +33,16 @@ export const DateField = ({
colorTheme = FormColorTheme.Blue,
...fieldContainerProps
}: DateFieldProps): JSX.Element => {
console.log('disable validaton', disableRequiredValidation)
const validationRules = useMemo(
() => createDateValidationRules(schema, disableRequiredValidation),
[schema, disableRequiredValidation],
)

console.log('validation rules', validationRules)
const { submissionId } = useParams()
console.log('submission id', submissionId)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this section needed?

Copy link
Contributor Author

@kathleenkhy kathleenkhy Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg, sorry! 😔 thanks for pointing this out!  🙏🏼

const isDateUnavailable = useCallback(
(date: Date) => {
const { selectedDateValidation } = schema.dateValidation
Expand Down Expand Up @@ -77,7 +83,7 @@ export const DateField = ({
<Controller
control={control}
name={schema._id}
rules={validationRules}
rules={disableRequiredValidation ? undefined : validationRules}
defaultValue=""
render={({ field: { value, onChange, ...field } }) => (
<DatePicker
Expand Down
Loading