Merge pull request #7651 from tchak/fix-autosave-en-construction
fix(autosave): on check condition requests do not send file inputs
This commit is contained in:
commit
cc3568df00
3 changed files with 92 additions and 3 deletions
|
@ -70,7 +70,14 @@ export class CheckConditionsController extends ApplicationController {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileInputs = form.querySelectorAll('input[type="file"]');
|
||||||
|
for (const input of fileInputs) {
|
||||||
|
input.setAttribute('disabled', 'disabled');
|
||||||
|
}
|
||||||
const formData = new FormData(form);
|
const formData = new FormData(form);
|
||||||
|
for (const input of fileInputs) {
|
||||||
|
input.removeAttribute('disabled');
|
||||||
|
}
|
||||||
formData.set('check_conditions', 'true');
|
formData.set('check_conditions', 'true');
|
||||||
|
|
||||||
return httpRequest(form.action, {
|
return httpRequest(form.action, {
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
import { suite, test, expect } from 'vitest';
|
import { suite, test, expect } from 'vitest';
|
||||||
|
|
||||||
import { show, hide, toggle } from './utils';
|
import {
|
||||||
|
show,
|
||||||
|
hide,
|
||||||
|
toggle,
|
||||||
|
isSelectElement,
|
||||||
|
isTextInputElement,
|
||||||
|
isCheckboxOrRadioInputElement
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
suite('@utils', () => {
|
suite('@utils', () => {
|
||||||
test('show', () => {
|
test('show', () => {
|
||||||
|
@ -26,4 +33,79 @@ suite('@utils', () => {
|
||||||
toggle(input);
|
toggle(input);
|
||||||
expect(input.classList.contains('hidden')).toBeFalsy();
|
expect(input.classList.contains('hidden')).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('isSelectElement', () => {
|
||||||
|
const select = document.createElement('select');
|
||||||
|
const input = document.createElement('input');
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
|
||||||
|
expect(isSelectElement(select)).toBeTruthy();
|
||||||
|
expect(isSelectElement(input)).toBeFalsy();
|
||||||
|
expect(isSelectElement(textarea)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'text';
|
||||||
|
expect(isSelectElement(input)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'email';
|
||||||
|
expect(isSelectElement(input)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'checkbox';
|
||||||
|
expect(isSelectElement(input)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'radio';
|
||||||
|
expect(isSelectElement(input)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'file';
|
||||||
|
expect(isSelectElement(input)).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isTextInputElement', () => {
|
||||||
|
const select = document.createElement('select');
|
||||||
|
const input = document.createElement('input');
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
|
||||||
|
expect(isTextInputElement(select)).toBeFalsy();
|
||||||
|
expect(isTextInputElement(input)).toBeTruthy();
|
||||||
|
expect(isTextInputElement(textarea)).toBeTruthy();
|
||||||
|
|
||||||
|
input.type = 'text';
|
||||||
|
expect(isTextInputElement(input)).toBeTruthy();
|
||||||
|
|
||||||
|
input.type = 'email';
|
||||||
|
expect(isTextInputElement(input)).toBeTruthy();
|
||||||
|
|
||||||
|
input.type = 'checkbox';
|
||||||
|
expect(isTextInputElement(input)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'radio';
|
||||||
|
expect(isTextInputElement(input)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'file';
|
||||||
|
expect(isTextInputElement(input)).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('isCheckboxOrRadioInputElement', () => {
|
||||||
|
const select = document.createElement('select');
|
||||||
|
const input = document.createElement('input');
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
|
||||||
|
expect(isCheckboxOrRadioInputElement(select)).toBeFalsy();
|
||||||
|
expect(isCheckboxOrRadioInputElement(input)).toBeFalsy();
|
||||||
|
expect(isCheckboxOrRadioInputElement(textarea)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'text';
|
||||||
|
expect(isCheckboxOrRadioInputElement(input)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'email';
|
||||||
|
expect(isCheckboxOrRadioInputElement(input)).toBeFalsy();
|
||||||
|
|
||||||
|
input.type = 'checkbox';
|
||||||
|
expect(isCheckboxOrRadioInputElement(input)).toBeTruthy();
|
||||||
|
|
||||||
|
input.type = 'radio';
|
||||||
|
expect(isCheckboxOrRadioInputElement(input)).toBeTruthy();
|
||||||
|
|
||||||
|
input.type = 'file';
|
||||||
|
expect(isCheckboxOrRadioInputElement(input)).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -297,7 +297,7 @@ export function isTextInputElement(
|
||||||
): element is HTMLInputElement {
|
): element is HTMLInputElement {
|
||||||
return (
|
return (
|
||||||
['INPUT', 'TEXTAREA'].includes(element.tagName) &&
|
['INPUT', 'TEXTAREA'].includes(element.tagName) &&
|
||||||
element.type != 'checkbox' &&
|
typeof element.type == 'string' &&
|
||||||
element.type != 'radio'
|
!['checkbox', 'radio', 'file'].includes(element.type)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue