issue: useFieldArray incorrectly treats value of 0 as empty value #12018
Unanswered
deshiknaves
asked this question in
Q&A
Replies: 2 comments 1 reply
-
looks like incorrect |
Beta Was this translation helpful? Give feedback.
1 reply
-
Same problem. It would be nice to have the possibility to provide primitive values (especially 0) to the field array. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Version Number
7.51.5
Codesandbox/Expo snack
https://codesandbox.io/p/sandbox/react-hook-form-array-zvvwvq?file=%2Fsrc%2FApp.tsx%3A23%2C12&layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clxfgtlc500063p6h3kazjlpx%2522%252C%2522sizes%2522%253A%255B100%252C0%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clxfgtlc500023p6h174pug6j%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clxfgtlc500033p6hzso2nh3v%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clxfgtlc500053p6hpxvski26%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clxfgtlc500023p6h174pug6j%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clxfgtlc500013p6hdviz1r6u%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522filepath%2522%253A%2522%252Fsrc%252Findex.tsx%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%252C%257B%2522id%2522%253A%2522clxfgyvan00023p6gcpna98ar%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522FILE%2522%252C%2522initialSelections%2522%253A%255B%257B%2522startLineNumber%2522%253A23%252C%2522startColumn%2522%253A12%252C%2522endLineNumber%2522%253A23%252C%2522endColumn%2522%253A12%257D%255D%252C%2522filepath%2522%253A%2522%252Fsrc%252FApp.tsx%2522%252C%2522state%2522%253A%2522IDLE%2522%257D%255D%252C%2522id%2522%253A%2522clxfgtlc500023p6h174pug6j%2522%252C%2522activeTabId%2522%253A%2522clxfgyvan00023p6gcpna98ar%2522%257D%252C%2522clxfgtlc500053p6hpxvski26%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clxfgtlc500043p6h41oga3mj%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522UNASSIGNED_PORT%2522%252C%2522port%2522%253A0%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522clxfgtlc500053p6hpxvski26%2522%252C%2522activeTabId%2522%253A%2522clxfgtlc500043p6h41oga3mj%2522%257D%252C%2522clxfgtlc500033p6hzso2nh3v%2522%253A%257B%2522tabs%2522%253A%255B%255D%252C%2522id%2522%253A%2522clxfgtlc500033p6hzso2nh3v%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Afalse%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D
Steps to reproduce
First
Add
0
in the fieldAdd
Second
Add
1
in the new fieldAdd
2
in the new fieldAdd
3
in the new field2
delete
Add
Expected behaviour
It should add a new field in the first scenario.
The problem is that
_getFieldArray
uses theutils/compact
method which uses.filter(Boolean)
. For a number field0
is a filled value and so we should be able to add another field.To me it feels like it should be an option if the values should be compacted or not. For example in the second example, I would expect it to add another field at the end.
What browsers are you seeing the problem on?
Edge
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions