A lightweight Application that renders a dialog containing a form with arbitrary content, and some buttons.

const proceed = await foundry.applications.api.DialogV2.confirm({
content: "Are you sure?",
rejectClose: false,
modal: true
});
if ( proceed ) console.log("Proceed.");
else console.log("Do not proceed.");
let guess;
try {
guess = await foundry.applications.api.DialogV2.prompt({
window: { title: "Guess a number between 1 and 10" },
content: '<input name="guess" type="number" min="1" max="10" step="1" autofocus>',
ok: {
label: "Submit Guess",
callback: (event, button, dialog) => button.form.elements.guess.valueAsNumber
}
});
} catch {
console.log("User did not make a guess.");
return;
}
const n = Math.ceil(CONFIG.Dice.randomUniform() * 10);
if ( n === guess ) console.log("User guessed correctly.");
else console.log("User guessed incorrectly.");
new foundry.applications.api.DialogV2({
window: { title: "Choose an option" },
content: `
<label><input type="radio" name="choice" value="one" checked> Option 1</label>
<label><input type="radio" name="choice" value="two"> Option 2</label>
<label><input type="radio" name="choice" value="three"> Options 3</label>
`,
buttons: [{
action: "choice",
label: "Make Choice",
default: true,
callback: (event, button, dialog) => button.form.elements.choice.value
}, {
action: "all",
label: "Take All"
}],
submit: result => {
if ( result === "all" ) console.log("User picked all options.");
else console.log(`User picked option: ${result}`);
}
}).render({ force: true });

Hierarchy (View Summary)

Constructors

Properties

Application instance configuration options.

position: ApplicationPosition = ...

The current position of the application with respect to the window.document.body.

tabGroups: Record<string, null | string> = ...

If this Application uses tabbed navigation groups, this mapping is updated whenever the changeTab method is called. Reports the active tab for each group, with a value of null indicating no tab is active. Subclasses may override this property to define default tabs for each group.

_appId: number = 0

An incrementing integer Application ID.

_maxZ: number = ...

The current maximum z-index of any displayed Application.

BASE_APPLICATION: typeof ApplicationV2 = ApplicationV2

Designates which upstream Application class in this class' inheritance chain is the base application. Any DEFAULT_OPTIONS of super-classes further upstream of the BASE_APPLICATION are ignored. Hook events for super-classes further upstream of the BASE_APPLICATION are not dispatched.

DEFAULT_OPTIONS: {
    classes: string[];
    form: { closeOnSubmit: boolean };
    id: string;
    tag: string;
    window: { frame: boolean; minimizable: boolean; positioned: boolean };
} = ...
emittedEvents: readonly ["render", "close", "position"] = ...
RENDER_STATES: Record<string, number> = ...

The sequence of rendering states that describe the Application life-cycle.

TABS: Record<string, ApplicationTabsConfiguration> = {}

Configuration of application tabs, with an entry per tab group.

Accessors

  • get classList(): DOMTokenList

    The CSS class list of this Application instance

    Returns DOMTokenList

  • get element(): HTMLElement

    The HTMLElement which renders this Application into the DOM.

    Returns HTMLElement

  • get form(): null | HTMLFormElement

    Does this Application have a top-level form element?

    Returns null | HTMLFormElement

  • get hasFrame(): boolean

    Does this Application instance render within an outer window frame?

    Returns boolean

  • get id(): string

    The HTML element ID of this Application instance. This provides a readonly view into the internal ID used by this application. This getter should not be overridden by subclasses, which should instead configure the ID in DEFAULT_OPTIONS or by defining a uniqueId during _initializeApplicationOptions.

    Returns string

  • get minimized(): boolean

    Is this Application instance currently minimized?

    Returns boolean

  • get rendered(): boolean

    Is this Application instance currently rendered?

    Returns boolean

  • get state(): number

    The current render state of the Application.

    Returns number

  • get title(): string

    A convenience reference to the title of the Application window.

    Returns string

  • get window(): {
        close: HTMLButtonElement;
        content: HTMLElement;
        controls: HTMLButtonElement;
        controlsDropdown: HTMLDivElement;
        header: HTMLElement;
        icon: HTMLElement;
        onDrag: Function;
        onResize: Function;
        pointerMoveThrottle: boolean;
        pointerStartPosition: ApplicationPosition;
        resize: HTMLElement;
        title: HTMLHeadingElement;
    }

    Convenience references to window header elements.

    Returns {
        close: HTMLButtonElement;
        content: HTMLElement;
        controls: HTMLButtonElement;
        controlsDropdown: HTMLDivElement;
        header: HTMLElement;
        icon: HTMLElement;
        onDrag: Function;
        onResize: Function;
        pointerMoveThrottle: boolean;
        pointerStartPosition: ApplicationPosition;
        resize: HTMLElement;
        title: HTMLHeadingElement;
    }

Methods

  • Returns void

  • Internal

    Wait for a CSS transition to complete for an element.

    Parameters

    • element: HTMLElement

      The element which is transitioning

    • timeout: number

      A timeout in milliseconds in case the transitionend event does not occur

    Returns Promise<void>

  • Internal

    Perform an event in the application life-cycle. Await an internal life-cycle method defined by the class. Optionally dispatch an event for any registered listeners.

    Parameters

    • handler: Function

      A handler function to call

    • options: {
          async?: boolean;
          debugText?: string;
          eventName?: string;
          handlerArgs?: any[];
          hookArgs?: any[];
          hookName?: string;
          hookResponse?: boolean;
          parentClassHooks?: boolean;
      } = {}

      Options which configure event handling

      • Optionalasync?: boolean

        Await the result of the handler function?

      • OptionaldebugText?: string

        Debugging text to log for the event

      • OptionaleventName?: string

        An event name to dispatch for registered listeners

      • OptionalhandlerArgs?: any[]

        Arguments passed to the handler function

      • OptionalhookArgs?: any[]

        Arguments passed to the requested hook function

      • OptionalhookName?: string

        A hook name to dispatch for this and all parent classes

      • OptionalhookResponse?: boolean

        Add the handler response to hookArgs

      • OptionalparentClassHooks?: boolean

        Call hooks for parent classes in the inheritance chain?

    Returns void | Promise<void>

    A promise which resoles once the handler is complete if async is true

  • Parameters

    • options: any

    Returns any

  • Parameters

    • _context: any
    • _options: any

    Returns Promise<void>

  • Parameters

    • _context: any
    • _options: any

    Returns Promise<HTMLFormElement>

  • Parameters

    • result: any
    • content: any
    • _options: any

    Returns void

  • Add a new event listener for a certain type of event.

    Parameters

    • type: string

      The type of event being registered for

    • listener: EmittedEventListener

      The listener function called when the event occurs

    • Optionaloptions: { once?: boolean } = {}

      Options which configure the event listener

      • Optionalonce?: boolean

        Should the event only be responded to once and then removed

    Returns void

  • Bring this Application window to the front of the rendering stack by increasing its z-index. Once ApplicationV1 is deprecated we should switch from _maxZ to ApplicationV2#maxZ We should also eliminate ui.activeWindow in favor of only ApplicationV2#frontApp

    Returns void

  • Change the active tab within a tab group in this Application instance.

    Parameters

    • tab: string

      The name of the tab which should become active

    • group: string

      The name of the tab group which defines the set of tabs

    • Optionaloptions: {
          event?: Event;
          force?: boolean;
          navElement?: HTMLElement;
          updatePosition?: boolean;
      } = {}

      Additional options which affect tab navigation

      • Optionalevent?: Event

        An interaction event which caused the tab change, if any

      • Optionalforce?: boolean

        Force changing the tab even if the new tab is already active

      • OptionalnavElement?: HTMLElement

        An explicit navigation element being modified

      • OptionalupdatePosition?: boolean

        Update application position after changing the tab?

    Returns void

  • Close the Application, removing it from the DOM.

    Parameters

    Returns Promise<DialogV2>

    A Promise which resolves to the closed Application instance

  • Restore the Application to its original dimensions.

    Returns Promise<void>

  • Minimize the Application, collapsing it to a minimal header.

    Returns Promise<void>

  • Render the Application, creating its HTMLElement and replacing its innerHTML. Add it to the DOM if it is not currently rendered and rendering is forced. Otherwise, re-render its contents.

    Parameters

    • Optionaloptions: boolean | ApplicationRenderOptions = {}

      Options which configure application rendering behavior. A boolean is interpreted as the "force" option.

    • Optional_options: ApplicationRenderOptions = {}

      Legacy options for backwards-compatibility with the original ApplicationV1#render signature.

    Returns Promise<DialogV2>

    A Promise which resolves to the rendered Application instance

  • Programmatically submit an ApplicationV2 instance which implements a single top-level form.

    Parameters

    • OptionalsubmitOptions: object = {}

      Arbitrary options which are supported by and provided to the configured form submission handler.

    Returns Promise<any>

    A promise that resolves to the returned result of the form submission handler, if any.

  • Toggle display of the Application controls menu. Only applicable to window Applications.

    Parameters

    • Optionalexpanded: boolean

      Set the controls visibility to a specific state. Otherwise, the visible state is toggled from its current value

    • Optionaloptions: { animate?: boolean } = {}

      Options to configure the toggling behavior.

      • Optionalanimate?: boolean

        Animate the controls toggling.

    Returns Promise<void>

    A Promise which resolves once the control expansion animation is complete

  • Protected

    Test whether this Application is allowed to be rendered.

    Parameters

    Returns false | void

    Return false to prevent rendering

    An Error to display a warning message

  • Protected

    Modify the provided options passed to a render request.

    Parameters

    Returns void

  • Protected

    Create a ContextMenu instance used in this Application.

    Parameters

    • handler: () => ContextMenuEntry[]

      A handler function that provides initial context options

    • selector: string

      A CSS selector to which the ContextMenu will be bound

    • Optionaloptions: { container?: HTMLElement; hookName?: string; parentClassHooks?: boolean } = {}

      Additional options which affect ContextMenu construction

      • Optionalcontainer?: HTMLElement

        A parent HTMLElement which contains the selector target

      • OptionalhookName?: string

        The hook name

      • OptionalparentClassHooks?: boolean

        Whether to call hooks for the parent classes in the inheritance chain.

    Returns null | ContextMenu

    A created ContextMenu or null if no menu items were defined

  • Protected

    Iterate over header control buttons, filtering for controls which are visible for the current client.

    Returns Generator<ApplicationHeaderControlsEntry, any, any>

  • Protected

    Insert the application HTML element into the DOM. Subclasses may override this method to customize how the application is inserted.

    Parameters

    • element: HTMLElement

      The element to insert

    Returns void

  • Protected

    Handle changes to an input element within the form.

    Parameters

    • formConfig: ApplicationFormConfiguration

      The form configuration for which this handler is bound

    • event: Event

      An input change event within the form

    Returns void

  • Protected

    A generic event handler for action clicks which can be extended by subclasses. Action handlers defined in DEFAULT_OPTIONS are called first. This method is only called for actions which have no defined handler.

    Parameters

    • event: PointerEvent

      The originating click event

    • target: HTMLElement

      The capturing HTML element which defined a [data-action]

    Returns void

  • Protected

    Handle click events on a tab within the Application.

    Parameters

    • event: PointerEvent

    Returns void

  • Protected

    Actions performed after closing the Application. Post-close steps are not awaited by the close process.

    Parameters

    Returns void

  • Protected

    Handle keypresses within the dialog.

    Parameters

    • event: KeyboardEvent

      The triggering event.

    Returns void

  • Protected

    Actions performed after the Application is re-positioned.

    Parameters

    Returns void

  • Protected

    Handle submitting the dialog.

    Parameters

    • target: HTMLButtonElement

      The button that was clicked or the default button.

    • event: PointerEvent | SubmitEvent

      The triggering event.

    Returns Promise<DialogV2>

  • Protected

    Handle submission for an Application which uses the form element.

    Parameters

    • formConfig: ApplicationFormConfiguration

      The form configuration for which this handler is bound

    • event: Event | SubmitEvent

      The form submission event

    Returns Promise<void>

  • Protected

    Actions performed before closing the Application. Pre-close steps are awaited by the close process.

    Parameters

    Returns Promise<void>

  • Protected

    Prepare application rendering context data for a given render request. If exactly one tab group is configured for this application, it will be prepared automatically.

    Parameters

    Returns Promise<ApplicationRenderContext>

    Context data for the render operation

  • Protected

    Prepare application tab data for a single tab group.

    Parameters

    • group: string

      The ID of the tab group to prepare

    Returns Record<string, ApplicationTab>

  • Protected

    Actions performed before the Application is re-positioned. Pre-position steps are not awaited because setPosition is synchronous.

    Parameters

    Returns void

  • Protected

    Remove the application HTML element from the DOM. Subclasses may override this method to customize how the application element is removed.

    Parameters

    • element: HTMLElement

      The element to be removed

    Returns void

  • Protected

    Render configured buttons.

    Returns string

  • Protected

    Render the outer framing HTMLElement which wraps the inner HTML of the Application.

    Parameters

    Returns Promise<HTMLElement>

  • Protected

    When the Application is rendered, optionally update aspects of the window frame.

    Parameters

    Returns void

  • Protected

    Translate a requested application position updated into a resolved allowed position for the Application. Subclasses may override this method to implement more advanced positioning behavior.

    Parameters

    Returns ApplicationPosition

    Resolved Application positioning data

  • Internal

    The dialog query handler.

    Parameters

    • __namedParameters: { config: object; type: "input" | "wait" | "prompt" | "confirm" }

    Returns Promise<any>

  • A utility helper to generate a dialog with yes and no buttons.

    Parameters

    Returns Promise<any>

    Resolves to true if the yes button was pressed, or false if the no button was pressed. If additional buttons were provided, the Promise resolves to the identifier of the one that was pressed, or the value returned by its callback. If the dialog was dismissed, and rejectClose is false, the Promise resolves to null.

  • Iterate over the inheritance chain of this Application. The chain includes this Application itself and all parents until the base application is encountered.

    Returns Generator<typeof ApplicationV2, void, unknown>

  • A utility helper to generate a dialog for user input.

    Parameters

    Returns Promise<any>

    Resolves to the data of the form if the ok button was pressed, or the value returned by that button's callback. If additional buttons were provided, the Promise resolves to the identifier of the one that was pressed, or the value returned by its callback. If the dialog was dismissed, and rejectClose is false, the Promise resolves to null.

  • Parse a CSS style rule into a number of pixels which apply to that dimension.

    Parameters

    • style: string

      The CSS style rule

    • parentDimension: number

      The relevant dimension of the parent element

    Returns number | void

    The parsed style dimension in pixels

  • A utility helper to generate a dialog with a single confirmation button.

    Parameters

    Returns Promise<any>

    Resolves to the identifier of the button used to submit the dialog, or the value returned by that button's callback. If additional buttons were provided, the Promise resolves to the identifier of the one that was pressed, or the value returned by its callback. If the dialog was dismissed, and rejectClose is false, the Promise resolves to null.

  • Present an asynchronous Dialog query to a specific User for response.

    Parameters

    • user: any

      A User instance or a User id

    • type: "input" | "wait" | "prompt" | "confirm"

      The type of Dialog to present

    • Optionalconfig: object = {}

      Dialog configuration forwarded on to the Dialog.prompt, Dialog.confirm, Dialog.input, or Dialog.wait function depending on the query type. Callback options are not supported.

    Returns Promise<any>

    The query response or null if no response was provided

  • Wait for any images in the given element to load.

    Parameters

    • element: HTMLElement

      The element.

    Returns Promise<void>

  • Protected

    Redirect all clicks of buttons with action specifications to the submit handler.

    Parameters

    • ...this: any
    • event: PointerEvent

      The originating click event.

    • target: HTMLButtonElement

      The button element that was clicked.

    Returns void