mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-06 04:44:16 +02:00
Avoid default type on name and item create dialogs (#1958)
This commit is contained in:
parent
318d00b47d
commit
98ce49b928
3 changed files with 36 additions and 0 deletions
|
|
@ -446,3 +446,33 @@ Hooks.on('canvasTearDown', canvas => {
|
||||||
Hooks.on('canvasReady', canas => {
|
Hooks.on('canvasReady', canas => {
|
||||||
game.system.registeredTriggers.registerSceneTriggers(canvas.scene);
|
game.system.registeredTriggers.registerSceneTriggers(canvas.scene);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Make the user to select a document type, instead of having a default doc type for them to accidentally keep */
|
||||||
|
Hooks.on('renderDialogV2', (_dialog, html) => {
|
||||||
|
if (!html.classList.contains('dialog')) return;
|
||||||
|
const cls = html.classList.contains('item-create')
|
||||||
|
? documents.DHItem.implementation
|
||||||
|
: html.classList.contains('actor-create')
|
||||||
|
? documents.DhpActor.implementation
|
||||||
|
: null;
|
||||||
|
if (!cls) return;
|
||||||
|
|
||||||
|
const form = html.querySelector('form');
|
||||||
|
const submit = html.querySelector('button[type=submit]');
|
||||||
|
const select = html.querySelector('select[name=type]');
|
||||||
|
const nameInput = html.querySelector('input[name=name]');
|
||||||
|
if (!form || !select || !submit || !nameInput) return;
|
||||||
|
|
||||||
|
nameInput.placeholder = cls.defaultName({});
|
||||||
|
const emptyOption = document.createElement('option');
|
||||||
|
emptyOption.value = '';
|
||||||
|
emptyOption.selected = true;
|
||||||
|
select.required = true;
|
||||||
|
select.prepend(emptyOption);
|
||||||
|
submit.addEventListener('click', event => {
|
||||||
|
if (!form.reportValidity()) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ export default class DhpActor extends Actor {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static createDialog(data, createOptions, options, renderOptions) {
|
||||||
|
options.classes = [options.classes ?? [], 'actor-create'].flat(); // handled in hook
|
||||||
|
return super.createDialog(data, createOptions, options, renderOptions);
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ export default class DHItem extends foundry.documents.Item {
|
||||||
/** @inheritdoc */
|
/** @inheritdoc */
|
||||||
static async createDialog(data = {}, createOptions = {}, options = {}) {
|
static async createDialog(data = {}, createOptions = {}, options = {}) {
|
||||||
const { folders, types, template, context = {}, ...dialogOptions } = options;
|
const { folders, types, template, context = {}, ...dialogOptions } = options;
|
||||||
|
dialogOptions.classes = [options.classes ?? [], 'item-create'].flat(); // handled in hook
|
||||||
|
|
||||||
if (types?.length === 0) {
|
if (types?.length === 0) {
|
||||||
throw new Error('The array of sub-types to restrict to must not be empty.');
|
throw new Error('The array of sub-types to restrict to must not be empty.');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue