RC-91 | Add dropdown option support

This commit is contained in:
Oliver-Akins 2025-01-11 20:04:27 -07:00
parent fb52e1b58d
commit 8d92040230
6 changed files with 76 additions and 12 deletions

View file

@ -0,0 +1,38 @@
import { localizer } from "../../utils/Localizer.mjs";
import { options } from "../options.mjs";
const { randomID } = foundry.utils;
export function dropdownInput(input, data) {
const label = localizer(input.label);
const id = `${data.meta.idp}-${randomID(10)}`;
if (!data.meta.editable) {
return `<div data-input-type="dropdown">
<span class="label">${label}</span>
<span class="value">${data.meta.limited ? `???` : input.value}</span>
</div>`;
};
if (!input.options.length) {
throw new Error(`dropdown type inputs must have some options`);
};
return `<div data-input-type="dropdown">
<label
for="${id}"
>
${label}
</label>
<select
id="${id}"
name="${input.path}"
>
${options(
input.value,
input.options,
{ hash: { localize: true }},
)}
</select>
</div>`;
};

View file

@ -1,3 +1,4 @@
import { dropdownInput } from "./dropdownInput.mjs";
import { numberInput } from "./numberInput.mjs";
import { stringSet } from "./stringSet.mjs";
@ -5,7 +6,7 @@ const inputTypes = {
"string-set": stringSet,
integer: numberInput,
bar: displayOnly,
dropdown: displayOnly,
dropdown: dropdownInput,
boolean: displayOnly,
};
@ -17,6 +18,7 @@ export function formFields(inputs, opts) {
const fields = [];
for (const input of inputs) {
if (inputTypes[input.type] == null) { continue };
input.value = Handlebars.escapeExpression(input.value);
fields.push(inputTypes[input.type](input, opts.data.root));
};
return fields.join(opts.hash?.joiner ?? `<hr />`);