Replies: 5 comments 4 replies
-
What do you mean by serialised boolean value?
|
Beta Was this translation helpful? Give feedback.
-
useForm({ defaultValues: {
...,
finally: {
active: false,
...
}
} It producess this HTML output: <fieldset>
<legend>Finally...</legend>
<div class="input-column">
<label>
<input name="finally.active" ... type="checkbox" value="false">Are you active?
</label>
...
</div>
</fieldset>
|
Beta Was this translation helpful? Give feedback.
-
Those are your implementation detail, this is not related to a bug in this library and we don't serialize in the |
Beta Was this translation helpful? Give feedback.
-
My expectation would be for |
Beta Was this translation helpful? Give feedback.
-
This is not a bug of If you want to get boolean value, you can just apply your overridden Working demo: https://stackblitz.com/edit/react-ts-ixfyvb?file=components%2FControlField.tsx,helpers.ts |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Version Number
7.43.9
Codesandbox/Expo snack
https://stackblitz.com/edit/react-ts-cntuap
Steps to reproduce
I have a form with a couple of fieldsets using custom components:
QFieldsetOne
—group ofCheckbox
components withregister
function (uncontrolled, differentname
)QFieldsetTwo
—group ofCheckbox
components rendered by customControlField
adapter (controlled, samename
)QFieldsetThree
—Textarea
and a group ofCheckbox
rendered by customControlField
adapter (controlled, differentname
)react-hook-form
is settingvalue
attribute as a stringified boolean oninput[type=checkbox]
when usinguseController
hook (QFieldsetThree
). This does not happen when usingregister
function (QFieldsetOne
) or an array of controlled checkboxes (QFieldsetTwo
)Expected behaviour
I would expect
useController
to setchecked
property onfield
object produced byuseController
hook and not serialize it asfield.value
property when it is a boolean.An example in the official documentation of
Checkboxes
component use internal state and it might make sense in this case where value is an array, but a group of checkboxes does not necessarily need to have the samename
or be indexed, and in those casesreact-hook-form
is less helpful by forcing a stringvalue
for booleans.BTW, how else should
defaultValues
be structured or transformed before being passed touseForm
hook to work with objects containing properties that are boolean?What browsers are you seeing the problem on?
Firefox, Chrome, Safari, Edge
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions