Add an error block and validation to help ensure users know when they messed up the block type

This commit is contained in:
Oliver-Akins 2025-07-26 10:53:37 -06:00
parent 7796c82962
commit ce65e3a516
3 changed files with 32 additions and 6 deletions

View file

@ -2,6 +2,14 @@ import { __ID__, filePath } from "../consts.mjs";
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
const validInputTypes = [
`checkbox`,
`details`,
`error`,
`input`,
`select`,
];
export class Ask extends HandlebarsApplicationMixin(ApplicationV2) {
static DEFAULT_OPTIONS = {
tag: `dialog`,
@ -32,11 +40,7 @@ export class Ask extends HandlebarsApplicationMixin(ApplicationV2) {
static PARTS = {
inputs: {
template: filePath(`templates/Ask/inputs.hbs`),
templates: [
filePath(`templates/Ask/inputs/checkbox.hbs`),
filePath(`templates/Ask/inputs/details.hbs`),
filePath(`templates/Ask/inputs/input.hbs`),
],
templates: validInputTypes.map(type => filePath(`templates/Ask/inputs/${type}.hbs`)),
},
controls: {
template: filePath(`templates/Ask/controls.hbs`),
@ -69,6 +73,14 @@ export class Ask extends HandlebarsApplicationMixin(ApplicationV2) {
} = {}) {
super(options);
this.alwaysUseAnswerObject = alwaysUseAnswerObject;
for (const input of inputs) {
if (!validInputTypes.includes(input.type)) {
input.details = `Invalid input type provided: ${input.type}`;
input.type = `error`;
};
};
this._inputs = inputs;
this._description = description;
this._userOnCancel = onCancel;