Make the input sanitization apply to all sub-inputs
This commit is contained in:
parent
1d43be188e
commit
5159db3d33
1 changed files with 40 additions and 23 deletions
|
|
@ -55,29 +55,7 @@ export async function ask(
|
|||
};
|
||||
};
|
||||
|
||||
let autofocusClaimed = false;
|
||||
for (const i of data.inputs) {
|
||||
i.id ??= foundry.utils.randomID(16);
|
||||
i.key ??= i.label;
|
||||
|
||||
// Only ever allow one input to claim autofocus
|
||||
i.autofocus &&= !autofocusClaimed;
|
||||
autofocusClaimed ||= i.autofocus;
|
||||
|
||||
// Set the value's attribute name if it isn't specified explicitly
|
||||
if (i.type === `input`) {
|
||||
i.inputType ??= `text`;
|
||||
switch (i.inputType) {
|
||||
case `checkbox`:
|
||||
i.type = `checkbox`;
|
||||
delete i.valueAttribute;
|
||||
delete i.inputType;
|
||||
break;
|
||||
default:
|
||||
i.valueAttribute ??= `value`;
|
||||
};
|
||||
};
|
||||
};
|
||||
validateInputs(data.inputs);
|
||||
|
||||
const promise = new Promise((resolve) => {
|
||||
const app = new Ask({
|
||||
|
|
@ -102,6 +80,45 @@ export function size() {
|
|||
return dialogs.size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensures all of the inputs are correctly valid and performs any
|
||||
* mutations to them required in order to make them valid or assign
|
||||
* defaults for properties that are missing.
|
||||
*
|
||||
* @param {AskInput[]} inputs The array of inputs for the dialog
|
||||
* @param {boolean} [autofocusClaimed] Whether or not to allow
|
||||
* autofocusing an input
|
||||
*/
|
||||
function validateInputs(inputs, autofocusClaimed = false) {
|
||||
for (const i of inputs) {
|
||||
i.id ??= foundry.utils.randomID(16);
|
||||
i.key ??= i.label;
|
||||
|
||||
// Only ever allow one input to claim autofocus
|
||||
i.autofocus &&= !autofocusClaimed;
|
||||
autofocusClaimed ||= i.autofocus;
|
||||
|
||||
// Set the value's attribute name if it isn't specified explicitly
|
||||
if (i.type === `input`) {
|
||||
i.inputType ??= `text`;
|
||||
switch (i.inputType) {
|
||||
case `checkbox`:
|
||||
i.type = `checkbox`;
|
||||
delete i.valueAttribute;
|
||||
delete i.inputType;
|
||||
break;
|
||||
default:
|
||||
i.valueAttribute ??= `value`;
|
||||
};
|
||||
};
|
||||
|
||||
// Recurse on child inputs if required
|
||||
if (i.type === `collapse` && i.inputs?.length > 0) {
|
||||
validateInputs(i.inputs, autofocusClaimed);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export const DialogManager = {
|
||||
close,
|
||||
ask,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue