Commit 3ffddade authored by Tim Zallmann's avatar Tim Zallmann

Merge branch 'sh-workaround-ms-edge-form-bug' into 'master'

Fix ref switcher not working on Microsoft Edge

Closes #31373

See merge request gitlab-org/gitlab!19335
parents 9a4ca79b cf18b7f1
......@@ -4,7 +4,11 @@ export const serializeFormEntries = entries =>
export const serializeForm = form => {
const fdata = new FormData(form);
const entries = Array.from(fdata.keys()).map(key => {
const val = fdata.getAll(key);
let val = fdata.getAll(key);
// Microsoft Edge has a bug in FormData.getAll() that returns an undefined
// value for each form element that does not match the given key:
// https://github.com/jimmywarting/FormData/issues/80
val = val.filter(n => n);
return { name: key, value: val.length === 1 ? val[0] : val };
});
......
---
title: Fix ref switcher not working on Microsoft Edge
merge_request: 19335
author:
type: fixed
......@@ -70,5 +70,27 @@ describe('lib/utils/forms', () => {
bar: ['bar-value2', 'bar-value1'],
});
});
it('handles Microsoft Edge FormData.getAll() bug', () => {
const formData = [
{ type: 'checkbox', name: 'foo', value: 'foo-value1' },
{ type: 'text', name: 'bar', value: 'bar-value2' },
];
const form = createDummyForm(formData);
jest
.spyOn(FormData.prototype, 'getAll')
.mockImplementation(name =>
formData.map(elem => (elem.name === name ? elem.value : undefined)),
);
const data = serializeForm(form);
expect(data).toEqual({
foo: 'foo-value1',
bar: 'bar-value2',
});
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment