From ce65e3a516d34d583870d43608ae2e591319f18f Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 26 Jul 2025 10:53:37 -0600 Subject: [PATCH] Add an error block and validation to help ensure users know when they messed up the block type --- module/apps/Ask.mjs | 22 +++++++++++++++++----- styles/Apps/Ask.css | 13 ++++++++++++- templates/Ask/inputs/error.hbs | 3 +++ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 templates/Ask/inputs/error.hbs diff --git a/module/apps/Ask.mjs b/module/apps/Ask.mjs index 472cfbf..3aa2a5d 100644 --- a/module/apps/Ask.mjs +++ b/module/apps/Ask.mjs @@ -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; diff --git a/styles/Apps/Ask.css b/styles/Apps/Ask.css index f0fb24e..f7bb78e 100644 --- a/styles/Apps/Ask.css +++ b/styles/Apps/Ask.css @@ -36,8 +36,19 @@ p { margin: 0; - grid-column: 1 / -1; text-indent: 1em; + + &.error { + font-size: 1.1rem; + padding: 6px 8px; + box-shadow: 0 0 10px var(--color-shadow-dark); + color: var(--color-text-light-1); + border-radius: 5px; + text-align: center; + background: var(--color-level-error-bg); + border: 1px solid var(--color-level-error); + text-indent: 0; + } } input[type="checkbox"] { diff --git a/templates/Ask/inputs/error.hbs b/templates/Ask/inputs/error.hbs new file mode 100644 index 0000000..6fb1086 --- /dev/null +++ b/templates/Ask/inputs/error.hbs @@ -0,0 +1,3 @@ +

+ {{ details }} +

\ No newline at end of file