Replies: 3 comments 5 replies
-
please follow the issue template when you report an issue. https://github.com/react-hook-form/react-hook-form/search?q=exact |
Beta Was this translation helpful? Give feedback.
-
Thank you, I do see in the source code now that I still have a question though, of how can a dynamic form field name be watched by name, for a form field like this? <EditableInput {...register(`${listItem.id}.quantity`)} /> The implementation that I see of (
name?: T,
signalName?: string,
exact?: boolean,
) =>
exact && signalName
? name === signalName
: !name ||
!signalName ||
name === signalName ||
convertToArrayPayload(name).some(
(currentName) =>
currentName &&
(currentName.startsWith(signalName) ||
signalName.startsWith(currentName)),
); so this looks like when using (
name?: T,
signalName?: string,
exact?: boolean,
) =>
exact && signalName
? name === signalName
: !name ||
!signalName ||
name === signalName ||
convertToArrayPayload(name).some(
(currentName) =>
currentName &&
currentName.includes(signalName) ),
); If this code is changed to use Also, should the code be doing this check? (currentName.startsWith(signalName) ||
signalName.startsWith(currentName)) If we say What is the usecase this part of the match is addressing? Thanks, |
Beta Was this translation helpful? Give feedback.
-
@bluebill1049 If I have this example, using nested object form data - <EditableInput {...register(`${listItem.id}.quantity`)} /> and I provide a This is why I suggested that Thanks. |
Beta Was this translation helpful? Give feedback.
-
Version Number
7.12.2
Codesandbox/Expo snack
n/a
Steps to reproduce
Expected behaviour
@bluebill1049
Bill,
In the RHF docs for
useWatch
, it shows an option forexact
:This makes it sound like the default behavior is that provided field names in the
{name: ['fieldX', 'fieldY']}
option would be matched non-exactly. I've looked at the source code, and I don't see any reference to theexact
prop - it looks like the watched field names are always matched directly by the provided field name props.This is causing a problem with nested form objects, because a) there's no way to provide the exact name of a dynamically-generated nested field, and b) the current logic won't match such a field by the static part of the name.
As an example, we have a table that is represented in RHF with fileds like this:
So, the actual nested field name will be something like
1234.quantity
,1235.quantity
, etc.How can we make this work with the
useWatch
option forname
?What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions