Add an error block and validation to help ensure users know when they messed up the block type
This commit is contained in:
parent
7796c82962
commit
ce65e3a516
3 changed files with 32 additions and 6 deletions
|
|
@ -2,6 +2,14 @@ import { __ID__, filePath } from "../consts.mjs";
|
||||||
|
|
||||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||||
|
|
||||||
|
const validInputTypes = [
|
||||||
|
`checkbox`,
|
||||||
|
`details`,
|
||||||
|
`error`,
|
||||||
|
`input`,
|
||||||
|
`select`,
|
||||||
|
];
|
||||||
|
|
||||||
export class Ask extends HandlebarsApplicationMixin(ApplicationV2) {
|
export class Ask extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
static DEFAULT_OPTIONS = {
|
static DEFAULT_OPTIONS = {
|
||||||
tag: `dialog`,
|
tag: `dialog`,
|
||||||
|
|
@ -32,11 +40,7 @@ export class Ask extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
static PARTS = {
|
static PARTS = {
|
||||||
inputs: {
|
inputs: {
|
||||||
template: filePath(`templates/Ask/inputs.hbs`),
|
template: filePath(`templates/Ask/inputs.hbs`),
|
||||||
templates: [
|
templates: validInputTypes.map(type => filePath(`templates/Ask/inputs/${type}.hbs`)),
|
||||||
filePath(`templates/Ask/inputs/checkbox.hbs`),
|
|
||||||
filePath(`templates/Ask/inputs/details.hbs`),
|
|
||||||
filePath(`templates/Ask/inputs/input.hbs`),
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
controls: {
|
controls: {
|
||||||
template: filePath(`templates/Ask/controls.hbs`),
|
template: filePath(`templates/Ask/controls.hbs`),
|
||||||
|
|
@ -69,6 +73,14 @@ export class Ask extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
} = {}) {
|
} = {}) {
|
||||||
super(options);
|
super(options);
|
||||||
this.alwaysUseAnswerObject = alwaysUseAnswerObject;
|
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._inputs = inputs;
|
||||||
this._description = description;
|
this._description = description;
|
||||||
this._userOnCancel = onCancel;
|
this._userOnCancel = onCancel;
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,19 @@
|
||||||
|
|
||||||
p {
|
p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
grid-column: 1 / -1;
|
|
||||||
text-indent: 1em;
|
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"] {
|
input[type="checkbox"] {
|
||||||
|
|
|
||||||
3
templates/Ask/inputs/error.hbs
Normal file
3
templates/Ask/inputs/error.hbs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<p class="error">
|
||||||
|
{{ details }}
|
||||||
|
</p>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue