Skip to content

Fix <SaveButton> form dirty status check#10997

Merged
slax57 merged 4 commits intomasterfrom
fix-save-button-dirty-check
Oct 24, 2025
Merged

Fix <SaveButton> form dirty status check#10997
slax57 merged 4 commits intomasterfrom
fix-save-button-dirty-check

Conversation

@djhi
Copy link
Contributor

@djhi djhi commented Oct 20, 2025

Problem

In react-hook-form versions greater than 7.53.0 (only tested 7.53.2), fields that are not dirty are still present in the dirtyFields state but with a false value. However, our current dirty check in <SaveButton> only check whether the dirtyFields state has object keys.

Solution

Actually check whether any of the dirtyFields state keys have a true value to determine the dirty status.

How To Test

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date

Also, please make sure to read the contributing guidelines.

@djhi djhi added the RFR Ready For Review label Oct 20, 2025
@slax57 slax57 requested review from Copilot and slax57 October 20, 2025 12:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fix SaveButton dirty state detection to align with react-hook-form ≥ 7.53.x where dirtyFields includes keys with false values.

  • Replace naive key-length check with a recursive hasDirtyFields function.
  • Add a ComplexForm Storybook story and a corresponding test to validate behavior with nested/array fields.

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/ra-ui-materialui/src/button/SaveButton.tsx Introduces hasDirtyFields to properly compute isDirty from dirtyFields, and uses lodash isEmpty for array-item handling.
packages/ra-ui-materialui/src/button/SaveButton.stories.tsx Adds ComplexForm story to reproduce and visualize dirty state in complex forms (arrays of objects).
packages/ra-ui-materialui/src/button/SaveButton.spec.tsx Adds a test to ensure SaveButton enables/disables correctly with nested/array fields and updates a test title for clarity.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@slax57 slax57 mentioned this pull request Oct 22, 2025
@slax57 slax57 added this to the 5.12.2 milestone Oct 24, 2025
@slax57 slax57 merged commit bdcee65 into master Oct 24, 2025
8 of 10 checks passed
@slax57 slax57 deleted the fix-save-button-dirty-check branch October 24, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

3 participants