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

fix: added moving hidden input to the form bottom #2899

Merged
merged 5 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/client/sandbox/node/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ export default class ElementSandbox extends SandboxBase {
for (const child of childNodesArray)
this._onElementAdded(child);

if (domUtils.getTagName(parent) === 'form')
hiddenInfo.moveInputToFormBottom(parent as HTMLFormElement);

return result;
}

Expand Down Expand Up @@ -1004,8 +1007,9 @@ export default class ElementSandbox extends SandboxBase {

addFileInputInfo (el: HTMLElement): void {
const infoManager = this._uploadSandbox.infoManager;
const files = infoManager.getFiles(el);

hiddenInfo.addInputInfo(el, infoManager.getFiles(el), infoManager.getValue(el));
hiddenInfo.addInputInfo(el, files, infoManager.getValue(el));
}

onIframeAddedToDOM (iframe: HTMLIFrameElement | HTMLFrameElement): void {
Expand Down
8 changes: 8 additions & 0 deletions src/client/sandbox/upload/hidden-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ export function removeInputInfo (input) {

return false;
}

export function moveInputToFormBottom (form: HTMLFormElement) {
const inputSelector = '[name="' + INTERNAL_ATTRS.uploadInfoHiddenInputName + '"]';
Aleksey28 marked this conversation as resolved.
Show resolved Hide resolved
const inputElement = nativeMethods.elementQuerySelector.call(form, inputSelector);

if (inputElement)
nativeMethods.appendChild.call(form, inputElement);
}
17 changes: 17 additions & 0 deletions test/client/fixtures/sandbox/upload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ test('hidden input should not affect both the length/count value and the element
});
});

test('hidden input should not affect on getting element by index in multilevel form', function () {
var form = document.createElement('form');

var input1 = $('<label><input type="file"></label>')[0];
var input2 = $('<input type="checkbox">')[0];

document.body.appendChild(form);

form.appendChild(input1);
form.appendChild(input2);

strictEqual(input1, form.childNodes[0]);
strictEqual(input2, form.childNodes[1]);

form.parentNode.removeChild(form);
});

test('get/set upload info', function () {
var fileInputWithoutForm = $('<input type="file">')[0];
var fileInputWithForm = $('<form><input type="file"></form>').children()[0];
Expand Down