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

Fix clearing a nested filter re-renders the previous value when navigating back to the list #9491

Merged
merged 3 commits into from
Dec 4, 2023

Conversation

slax57
Copy link
Contributor

@slax57 slax57 commented Dec 4, 2023

Problem

Due to a regression brought by #8637 , clearing a filter with a nested value would indeed clear its value in the filter object, but would prevent react-hook-form from clearing the value in the form state.
Hence, this could lead to having the previous value come back when leaving the list and then navigating back. (especially visible when using an <AutocompleteArrayInput> as filter)

Solution

Partially revert the change brought by #8637 .

#8637 Seems to indicate the way to deal with nested values is

        <TextInput
            label="Nested"
            source="nested"
            defaultValue={{ foo: 'bar' }}
            format={v => v?.foo || ''}
            parse={v => ({ foo: v })}
        />,

Whereas it actually should be

        <TextInput label="Nested" source="nested.foo" defaultValue="bar" />,

@slax57 slax57 added the RFR Ready For Review label Dec 4, 2023
Comment on lines -288 to -290
if (nestedInputValue === '') {
return acc;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix

@djhi djhi merged commit 67c57d7 into master Dec 4, 2023
9 checks passed
@djhi djhi deleted the nested-aai-filter branch December 4, 2023 14:15
@fzaninotto fzaninotto added this to the 4.16.2 milestone Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants