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

DatePicker/DateTimePicker/TimePicker clobber validate function #286

Open
2 tasks done
jlai opened this issue Jul 8, 2024 · 1 comment
Open
2 tasks done

DatePicker/DateTimePicker/TimePicker clobber validate function #286

jlai opened this issue Jul 8, 2024 · 1 comment

Comments

@jlai
Copy link

jlai commented Jul 8, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

react-hook-forms allows you to pass either an object or a function as the validate param, e.g.

rules={{
  validate: (x) =>Number.isInteger(x)
}}

but react-hook-form-mui seems to expect only an object

You can work around this by nesting the rule:

rules={{
  validate: {
    workaround: (x) =>Number.isInteger(x)
  }
}}

but ideally that wouldn't be necessary.

Expected behavior 🤔

Passing a validate function in rules should just work, ideally. That might require reworking rulesTmp, however. One option might be to have rulesTmp put the user's validate function in a subproperty of validate, although it would mess with looking up errors manually from the errors object.

This might be OK if appropriately documented.

Steps to reproduce 🕹

Steps:

@sadik-malik
Copy link
Contributor

@jlai, the DatePicker/DateTimePicker/TimePicker components use the validate property within the rules prop as an object. This enables internal validations for props such as shouldDisableDate, shouldDisableMonth, disablePast, shouldDisableYear, minDate, and more.

If we treat validate as a function instead of an object, then it will leave us with no effective way to apply these internal validations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants