Skip to content

Commit

Permalink
fix: <Form> initial snapshot is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobJingleheimer committed Feb 29, 2024
1 parent 59f7107 commit 48ff716
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/react/Form/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function Form({
...props
}) {
const formElm = useRef();
const initValues = useRef(/** @type {ComposedData} */ ({})); // `useRef` to avoid needless re-renders
const initValues = useRef(/** @type {ComposedData} */ (null)); // `useRef` to avoid needless re-renders
const {
pristine,
touched,
Expand Down
12 changes: 11 additions & 1 deletion lib/react/Form/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ describe('Form', () => {
expect(spies.stopPropagationCalled).to.be.true;
});

it('should abort when form is pristine', () => {
it('should abort when delta is empty', () => {
let cbCalled = false;
const { event } = generateFakeSubmissionEvent({ attrs: { pristine: true } });
const fields = generateFieldData(false);

event.target.elements = [
fields.forename,
fields.surname,
fields.email,
fields.tel,
fields.age,
fields.newsletterOptin,
];

onSubmit(event, initValues, () => cbCalled = true);

Expand Down
4 changes: 2 additions & 2 deletions lib/react/Form/Form.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ describe('<Form>', () => {

fireEvent.submit(form);

expect(delta).to.eql(nV);
expect(all).to.eql({
expect(delta, 'delta').to.eql(nV);
expect(all, 'all').to.eql({
__proto__: null,
age: nV.age,
contactDetails: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form5",
"version": "3.2.2",
"version": "3.2.3",
"description": "A set of mostly unopinionated react components leveraging native APIs; supports controlled and uncontrolled state.",
"type": "module",
"files": [
Expand Down

0 comments on commit 48ff716

Please sign in to comment.