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

FormData constructed from a <form> element contains duplicate values #1426

Open
cmd-johnson opened this issue May 7, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@cmd-johnson
Copy link

Describe the bug
When constructing a FormData instance from an HTMLFormElement containing an input that has both an id and a name, the input's value appears twice in the form data.

To Reproduce

describe('FormData', () => {
  describe('Constructor', () => {
    it('Contains the value of named inputs with ids only once', () => {
      const form = document.createElement('form');
      const input = document.createElement('input');

      input.name = 'inputName';
      input.id = 'inputId';
      input.value = 'testing';

      form.appendChild(input);

      const formData = new window.FormData(form);

      expect(formData.getAll('inputName')).toEqual(['testing']);
    });
  });
});

Expected behavior
The resulting formData should only have a single value for the inputName key.
Calling formData.getAll('inputName') returns ['testing'].

Current behavior
Calling formData.getAll('inputName') returns ['testing', 'testing'].

Device:

  • OS: linux (manjaro)
  • Browser: N/A
  • Version: 14.10.1
@cmd-johnson cmd-johnson added the bug Something isn't working label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant