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

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

Closed
1 task done
PetrBorisov opened this issue Apr 18, 2024 · 2 comments
Closed
1 task done

Comments

@PetrBorisov
Copy link

PetrBorisov commented Apr 18, 2024

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
@bluebill1049
Copy link
Member

please use validate function instead.

@PetrBorisov
Copy link
Author

PetrBorisov commented Apr 19, 2024

@bluebill1049 I know about workarounds, but rules.pattern is not marked as deprecated and has this bug

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants