Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Controller changes checkbox behavior #11893

Closed
1 task done
bolivier opened this issue May 16, 2024 · 2 comments
Closed
1 task done

Controller changes checkbox behavior #11893

bolivier opened this issue May 16, 2024 · 2 comments
Labels
question Further information is requested

Comments

@bolivier
Copy link

bolivier commented May 16, 2024

Version Number

7.51.4

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/rhf-bug-report-r96rcd

Steps to reproduce

Click the "value 2" checkbox on both forms and see that without the controller, the expected behavior occurs, and with the controller, something different happens.

Expected behaviour

I would expect that wrapping the checkbox in a controller would not change this behavior.

What browsers are you seeing the problem on?

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bolivier
Copy link
Author

I managed to fix my test cases with this, but it doesn't work with existing test cases.

diff --git a/src/useController.ts b/src/useController.ts
index 9f81698a..574be9aa 100644
--- a/src/useController.ts
+++ b/src/useController.ts
@@ -135,6 +135,7 @@ export function useController<
             target: {
               value: getEventValue(event),
               name: name as InternalFieldName,
+              type: event.target.type,
             },
             type: EVENTS.CHANGE,
           }),
@@ -155,13 +156,8 @@ export function useController<
         const field = get(control._fields, name);
 
         if (field && elm) {
-          field._f.ref = {
-            focus: () => elm.focus(),
-            select: () => elm.select(),
-            setCustomValidity: (message: string) =>
-              elm.setCustomValidity(message),
-            reportValidity: () => elm.reportValidity(),
-          };
+          field._f.ref = elm;
+          field._f.refs.push(elm);
         }
       },
     },

@bluebill1049 bluebill1049 added the question Further information is requested label May 18, 2024
@bluebill1049
Copy link
Member

what i would suggestion, build a radio component which host inputs inside and wrapped with Controller.

@react-hook-form react-hook-form locked and limited conversation to collaborators May 19, 2024
@bluebill1049 bluebill1049 converted this issue into discussion #11902 May 19, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants