Skip to content

DatePicker/DateTimePicker/TimePicker clobber validate function #286

@jlai

Description

@jlai

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions