Skip to content

issue: Controller rules.pattern doesn't apply new value without explicit undefined #11796

Closed
@psborisov

Description

@psborisov

Version Number

7.51.3

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/thirsty-goldstine-n9rfhv?file=%2Fsrc%2FApp.tsx

Steps to reproduce

  1. Go to codesandbox example
  2. Type "message" into input
  3. Click "switch pattern" button
  4. Type "message" into input
  5. See error
image

Problem here is that after click on "switch pattern" I start to provide rules = {{ required: true }} property to controller without any explicit undefined for rules.pattern and Controller use "cached" value from previous rules property value


Workaround 1

rules={{
  ...rulesToUse,
  pattern: rulesToUse.pattern,
}}

Workaround 2

const rules2 = {
  // pattern: undefined,  <---- uncomment this line
  required: true,
};

P.S. I didn't try to catch same behaviour with register({rules}) maybe it's not a Controller specific behaviour

Expected behaviour

I expect that change of "rules" property will update rules.pattern property as well without explicit "undefined"

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions