Skip to content

Commit

Permalink
Merge pull request #4130 from m4theushw/fix-clone-button
Browse files Browse the repository at this point in the history
[RFR] Fix cloned record reverts values when submitting
  • Loading branch information
fzaninotto authored Dec 10, 2019
2 parents abc2323 + f48e9d9 commit 838ceaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cypress/integration/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ describe('Edit Page', () => {
);
});

it('should not revert values when saving a record that was cloned', () => {
EditPostPage.navigate();
cy.get(EditPostPage.elements.input('title')).should(el =>
expect(el).to.have.value('Sed quo et et fugiat modi')
);

EditPostPage.clone();
CreatePostPage.setInputValue('input', 'title', 'Lorem Ipsum');

// The next assertion has to occur immediately, thus CreatePostPage.submit() is not used
cy.get(CreatePostPage.elements.submitButton).click();

cy.get(CreatePostPage.elements.input('title')).then(el => {
expect(el).to.have.value('Lorem Ipsum');
});
});

it('should persit emptied inputs', () => {
EditPostPage.navigate();
EditPostPage.gotoTab(3);
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/form/useInitializeFormWithRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useInitializeFormWithRecord = record => {
}
});
});
}, [form, record]);
}, [form, JSON.stringify(record)]); // eslint-disable-line react-hooks/exhaustive-deps
};

export default useInitializeFormWithRecord;

0 comments on commit 838ceaf

Please sign in to comment.