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;

View file

@ -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"] {

View file

@ -0,0 +1,3 @@
<p class="error">
{{ details }}
</p>