Implement the custom options helper (closes #92)
This commit is contained in:
parent
0e8d1615a7
commit
7516e7b42b
3 changed files with 35 additions and 8 deletions
32
module/helpers/options.mjs
Normal file
32
module/helpers/options.mjs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* @typedef {object} Option
|
||||
* @property {string} [label]
|
||||
* @property {string|number} value
|
||||
* @property {boolean} [disabled]
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string | number} selected
|
||||
* @param {Array<Option | string>} opts
|
||||
*/
|
||||
export function options(selected, opts) {
|
||||
selected = Handlebars.escapeExpression(selected);
|
||||
const htmlOptions = [];
|
||||
|
||||
for (let opt of opts) {
|
||||
if (foundry.utils.getType(opt) === "string") {
|
||||
opt = { label: opt, value: opt };
|
||||
};
|
||||
opt.value = Handlebars.escapeExpression(opt.value);
|
||||
htmlOptions.push(
|
||||
`<option
|
||||
value="${opt.value}"
|
||||
${selected === opt.value ? "selected" : ""}
|
||||
${opt.disabled ? "disabled" : ""}
|
||||
>
|
||||
${opt.label}
|
||||
</option>`
|
||||
);
|
||||
};
|
||||
return htmlOptions.join(`\n`);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue