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: Field disabled state not correct on initial render #11239

Closed
1 task done
thomasdbock opened this issue Nov 28, 2023 · 3 comments
Closed
1 task done

issue: Field disabled state not correct on initial render #11239

thomasdbock opened this issue Nov 28, 2023 · 3 comments
Labels
question Further information is requested

Comments

@thomasdbock
Copy link
Contributor

thomasdbock commented Nov 28, 2023

Version Number

7.48.2

Codesandbox/Expo snack

https://codesandbox.io/p/sandbox/purple-frost-zfytqd

Steps to reproduce

  1. Go to https://codesandbox.io/p/sandbox/purple-frost-zfytqd
  2. Notice the "First name" field which is currently enabled
  3. Toggle the field state by pressing either button (toggle field)
  4. Notice the field is still enabled
  5. Toggle again (repeat step 3)
  6. Notice the field is now correctly disabled

Expected behaviour

Since the fieldState was disabled by default, I expect the field to have the disabled state when the page has finished rendering.

What browsers are you seeing the problem on?

Firefox, Chrome, Safari

Relevant log output

Not a log, but manually mapping each field property except the ref fixes this issue.

Code of Conduct

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

Not providing a disabled property in useForm also fixes this issue: https://codesandbox.io/p/sandbox/cranky-keldysh-pxd5hv

@bluebill1049
Copy link
Member

this is close to chicken and egg problem, we can either take field level > form level or form level > field level.

@bluebill1049 bluebill1049 added the question Further information is requested label Nov 28, 2023
@thomasdbock
Copy link
Contributor Author

thomasdbock commented Nov 28, 2023

Hey @bluebill1049
For me the case is as follows:
Form state is used as "edit mode on/off", field disable state is conditional with another checkbox controlling it (but default off).

I think if one of them is false, it should disable the field.
Right now the field is saying it's disabled, but it really isn't. In my use case, this is causing UX side effects since I have no clear way of knowing if it is truly disabled.

Then again, I never expect disabled: false to explicitly "enable" the fields if some other part is disabling it.
I considered it as an OR state (disabled: field.disabled || form.disabled)

thomasdbock pushed a commit to thomasdbock/react-hook-form that referenced this issue Nov 28, 2023
thomasdbock pushed a commit to thomasdbock/react-hook-form that referenced this issue Nov 29, 2023
bluebill1049 added a commit that referenced this issue Nov 29, 2023
…bled (#11241)

* fix(#11239): Set fields disabled state based on form and field disabled prop

* fix(#11239): If-check and unit test

* Update createFormControl.ts

---------

Co-authored-by: Thomas De Bock <thomas.de.bock@persgroep.net>
Co-authored-by: Beier (Bill) <bluebill1049@hotmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants