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

Example: Prompt the user to confirm an action.

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.");

Example: Prompt the user for some input.

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.");

Example: A custom dialog.

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 full)

Constructors

Properties

Application instance configuration options.

tabGroups: Record<string, 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. Subclasses may override this property to define default tabs for each group.

position: ApplicationPosition = ...

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

#id: string
#renderable: boolean = true

Flag that this Application instance is renderable. Applications are not renderable unless a subclass defines the _renderHTML and _replaceHTML methods.

#element: HTMLDivElement

The outermost HTMLElement of this rendered Application. For window applications this is ApplicationV2##frame. For non-window applications this ApplicationV2##content.

#content: HTMLElement

The HTMLElement within which inner HTML is rendered. For non-window applications this is the same as ApplicationV2##element.

#minimization: {
    active: boolean;
} = ...

Data pertaining to the minimization status of the Application.

Type declaration

  • active: boolean
#position: ApplicationPosition = ...

The rendered position of the Application.

#state: Readonly<{
    ERROR: -3;
    CLOSING: -2;
    CLOSED: -1;
    NONE: 0;
    RENDERING: 1;
    RENDERED: 2;
}> = ApplicationV2.RENDER_STATES.NONE

Type declaration

  • ERROR: -3
  • CLOSING: -2
  • CLOSED: -1
  • NONE: 0
  • RENDERING: 1
  • RENDERED: 2
#semaphore: Semaphore = ...

A Semaphore used to enqueue asynchronous operations.

#controlsExpanded: boolean = false

Is the window control buttons menu currently expanded?

#events: Record<string, Map<EmittedEventListener, {
    fn: EmittedEventListener;
    once: boolean;
}>> = {}

A mapping of registered events.

DEFAULT_OPTIONS: {
    id: string;
    classes: string[];
    tag: string;
    form: {
        closeOnSubmit: boolean;
    };
    window: {
        frame: boolean;
        positioned: boolean;
        minimizable: boolean;
    };
} = ...

The default configuration options which are assigned to every instance of this Application class.

Type declaration

  • id: string
  • classes: string[]
  • tag: string
  • form: {
        closeOnSubmit: boolean;
    }
    • closeOnSubmit: boolean
  • window: {
        frame: boolean;
        positioned: boolean;
        minimizable: boolean;
    }
    • frame: boolean
    • positioned: boolean
    • minimizable: boolean
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.

RENDER_STATES: Readonly<{
    ERROR: -3;
    CLOSING: -2;
    CLOSED: -1;
    NONE: 0;
    RENDERING: 1;
    RENDERED: 2;
}> = ...

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

Type declaration

  • ERROR: -3
  • CLOSING: -2
  • CLOSED: -1
  • NONE: 0
  • RENDERING: 1
  • RENDERED: 2
emittedEvents: readonly string[] = ...

Accessors

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

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

    • header: HTMLElement
    • resize: HTMLElement
    • title: HTMLHeadingElement
    • icon: HTMLElement
    • close: HTMLButtonElement
    • controls: HTMLButtonElement
    • controlsDropdown: HTMLDivElement
    • onDrag: Function
    • onResize: Function
    • pointerStartPosition: ApplicationPosition
    • pointerMoveThrottle: boolean
  • get classList(): DOMTokenList
  • The CSS class list of this Application instance

    Returns DOMTokenList

  • get id(): string
  • The HTML element ID of this Application instance.

    Returns string

  • get title(): string
  • A convenience reference to the title of the Application window.

    Returns string

  • get element(): HTMLElement
  • The HTMLElement which renders this Application into the DOM.

    Returns HTMLElement

  • get minimized(): boolean
  • Is this Application instance currently minimized?

    Returns boolean

  • get rendered(): boolean
  • Is this Application instance currently rendered?

    Returns boolean

  • get state(): Readonly<{
        ERROR: -3;
        CLOSING: -2;
        CLOSED: -1;
        NONE: 0;
        RENDERING: 1;
        RENDERED: 2;
    }>
  • The current render state of the Application.

    Returns Readonly<{
        ERROR: -3;
        CLOSING: -2;
        CLOSED: -1;
        NONE: 0;
        RENDERING: 1;
        RENDERED: 2;
    }>

  • get hasFrame(): boolean
  • Does this Application instance render within an outer window frame?

    Returns boolean

Methods

  • Initialize configuration options for the Application instance. The default behavior of this method is to intelligently merge options for each class with those of their parents.

    • Array-based options are concatenated
    • Inner objects are merged
    • Otherwise, properties in the subclass replace those defined by a parent

    Parameters

    • options: any

      Options provided directly to the constructor

    Returns any

    Configured options for the application instance

  • Parameters

    • _context: any
    • _options: any

    Returns Promise<HTMLFormElement>

  • Parameters

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

    Returns 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

    • Optional options: any = {}

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

    • Optional _options: any = {}

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

    Returns Promise<ApplicationV2<any, any>>

    A Promise which resolves to the rendered Application instance

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

    Parameters

    • Optional expanded: boolean

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

    Returns void

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

    Returns Promise<void>

  • Restore the Application to its original dimensions.

    Returns Promise<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

    • Optional options: {
          event: Event;
          navElement: HTMLElement;
          force: boolean;
          updatePosition: boolean;
      } = {}

      Additional options which affect tab navigation

      • event: Event

        An interaction event which caused the tab change, if any

      • navElement: HTMLElement

        An explicit navigation element being modified

      • force: boolean

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

      • updatePosition: boolean

        Update application position after changing the tab?

    Returns void

  • 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

  • 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>

  • Protected

    Render configured buttons.

    Returns string

  • 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 keypresses within the dialog.

    Parameters

    • event: KeyboardEvent

      The triggering event.

    Returns void

  • Protected

    Modify the provided options passed to a render request.

    Parameters

    • options: any

      Options which configure application rendering behavior

    Returns void

  • Protected

    Prepare application rendering context data for a given render request.

    Parameters

    • options: any

      Options which configure application rendering behavior

    Returns Promise<Object>

    Context data for the render operation

  • Protected

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

    Parameters

    • options: any

      Options which configure application rendering behavior

    Returns Promise<HTMLElement>

  • Protected

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

    Parameters

    • options: any

      Options provided at render-time

    Returns void

  • 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

    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

    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

  • Protected

    Test whether this Application is allowed to be rendered.

    Parameters

    • options: any

      Provided render options

    Returns false | void

    Return false to prevent rendering

    Throws

    An Error to display a warning message

  • Protected

    Actions performed before a first render of the Application.

    Parameters

    • context: Object

      Prepared context data

    • options: any

      Provided render options

    Returns Promise<void>

  • Protected

    Actions performed before any render of the Application. Pre-render steps are awaited by the render process.

    Parameters

    • context: Object

      Prepared context data

    • options: any

      Provided render options

    Returns Promise<void>

  • Protected

    Actions performed after any render of the Application. Post-render steps are not awaited by the render process.

    Parameters

    • context: Object

      Prepared context data

    • options: any

      Provided render options

    Returns void

  • Protected

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

    Parameters

    • options: any

      Provided render options

    Returns Promise<void>

  • Protected

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

    Parameters

    • options: any

      Provided render options

    Returns void

  • Protected

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

    Parameters

    Returns void

  • Protected

    Actions performed after the Application is re-positioned.

    Parameters

    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 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>

  • Manage the rendering step of the Application life-cycle. This private method delegates out to several protected methods which can be defined by the subclass.

    Parameters

    • Optional options: any

      Options which configure application rendering behavior

    Returns Promise<ApplicationV2<any, any>>

    A Promise which resolves to the rendered Application instance

  • Manage the closing step of the Application life-cycle. This private method delegates out to several protected methods which can be defined by the subclass.

    Parameters

    Returns Promise<ApplicationV2<any, any>>

    A Promise which resolves to the rendered Application instance

  • 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;
          handlerArgs: any[];
          debugText: string;
          eventName: string;
          hookName: string;
          hookArgs: any[];
      } = {}

      Options which configure event handling

      • async: boolean

        Await the result of the handler function?

      • handlerArgs: any[]

        Arguments passed to the handler function

      • debugText: string

        Debugging text to log for the event

      • eventName: string

        An event name to dispatch for registered listeners

      • hookName: string

        A hook name to dispatch for this and all parent classes

      • hookArgs: any[]

        Arguments passed to the requested hook function

    Returns Promise<void>

    A promise which resoles once the handler is complete

  • Handle initial pointerdown events inside a rendered Application.

    Parameters

    • event: PointerEvent

    Returns Promise<void>

  • Centralized handling of click events which occur on or within the Application frame.

    Parameters

    • event: PointerEvent

    Returns Promise<void>

  • Handle a click event on an element which defines a [data-action] handler.

    Parameters

    • event: PointerEvent

      The originating click event

    • target: HTMLElement

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

    Returns void

  • Handle click events on a tab within the Application.

    Parameters

    • event: PointerEvent

    Returns void

  • Begin capturing pointer events on the application frame.

    Parameters

    • event: PointerEvent

      The triggering event.

    • callback: Function

      The callback to attach to pointer move events.

    Returns void

  • End capturing pointer events on the application frame.

    Parameters

    • event: PointerEvent

      The triggering event.

    • callback: Function

      The callback to remove from pointer move events.

    Returns void

  • Handle a pointer move event while dragging or resizing the window frame.

    Parameters

    • event: PointerEvent

    Returns void | {
        dx: number;
        dy: number;
    }

    The amount the cursor has moved since the last frame, or undefined if the movement occurred between frames.

  • Begin dragging the Application position.

    Parameters

    • event: PointerEvent

    Returns void

  • Drag the Application position during mouse movement.

    Parameters

    • event: PointerEvent

    Returns void

  • Resize the Application during mouse movement.

    Parameters

    • event: PointerEvent

    Returns void

  • Double-click events on the window title are used to minimize or maximize the application.

    Parameters

    • event: PointerEvent

    Returns void

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

    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.

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

    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 the dialog was dismissed, and rejectClose is false, the Promise resolves to null.

  • Spawn a dialog and wait for it to be dismissed or submitted.

    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 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>

    See

    ApplicationV2.BASE_APPLICATION

    Generator

    Yields

  • 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

    The parsed style dimension in pixels

  • Protected

    Parameters

    • Rest ...this: any
    • event: PointerEvent

      The originating click event.

    • target: HTMLButtonElement

      The button element that was clicked.

    Returns void