Closed skorphil closed 7 months ago
institutions: [
{
name:"City Bank",
assets: [
{1}
{2}
]
},
{
name:"Bank of America",
assets: [
{1}
{2} // removing or adding asset will result in all `institutions.X` being dirty
]
}
]
however, all individual fields inside institutions.X are not dirty (when checked with dirtyFields
)
https://www.reddit.com/r/react/comments/1ax7bf4/usehookform_how_to_get_dirty_state_of_part_of/
It is not possible to just iterate thru dirtyFields
because this way it will not check if fields being added deleted
I'm stuck
Well, seems like it is possible to solve this by deep comparison of getValues(institutions[x]) and defaultValues(institutions[x])
Finally, implement this scenario by comparing defaultValues
and current Values
const institutionDefaultValues =
formState.defaultValues.institutions[
getInstitutionIndex(institutionName)
];
const institutionCurrentValues = getValues(institutionName);
const isChanged =
JSON.stringify(institutionDefaultValues) !==
JSON.stringify(institutionCurrentValues);
Prob the problem can be fixed by replacing numbers with a strings https://discord.com/channels/754891658327359538/1215263704233414727
When value inside Institution differs from defaultValues, the label should appear on the
InstitutionTab
.Probably can be achieved with built-in use-hook-form features like dirty state