SerenityJS
    Preparing search index...

    Class ModalForm<T>

    These forms are the must advanced type of form. These allow developers to add elements to request input from the player, rather than using buttons. The elements used in ModalForms are: dropdown, input, label, slider, stepSlider, and toggle.

    Example Usage

    import { ModalForm } from "@serenityjs/server-ui"

    // Create a new ModalForm instance and set the title and add elements
    const form = new ModalForm()
    form.title = "ModalForm Example"

    // A dropdown allows the player to select from a list of options
    form.dropdown("Dropdown Element", ["Option 1", "Option 2", "Option 3"], 1)

    // An input allows the player to enter text
    form.input("Input Element", "Input Placeholder", "Input Text")

    // A slider allows the player to select a value within a range
    form.slider("Slider Element", 0, 100, 10)

    // A step slider allows the player to select a value from a list of options
    form.stepSlider("Step Slider Element", ["Step 1", "Step 2", "Step 3"], 1)

    // A toggle allows the player to enable or disable an option
    form.toggle("Toggle Element", true)

    // A label displays text to the player
    form.label("Label Element", "Label Text")

    // Show the form to the player
    form.show(player)
    .then((response) => {})
    .catch((rejected) => {})

    Type Parameters

    • T = unknown[]

    Hierarchy (View Summary)

    Index

    Constructors

    • Create a new server-sided modal form.

      Type Parameters

      • T = unknown[]

      Parameters

      • title: string

        The title of the form.

      • Optionalsubmit: string

        The text of the submit button; defaults to "Submit".

      Returns ModalForm<T>

    Properties

    content: unknown[] = []

    The content of the form.

    formId: number = ++Form.formId

    The form id of the form.

    submit: string

    The sumbit button text.

    title: string

    The title of the form.

    type: Modal = ModalFormType.Modal

    The type of form.

    formId: number = 0

    The next form id to use when creating a new form.

    Methods

    • Adds a dropdown menu to the form.

      Parameters

      • text: string

        The text of the dropdown menu

      • options: string[]

        The options of the dropdown menu

      • defaultIndex: number = 0

        The default index of the dropdown menu

      Returns this

    • Adds a text input to the form.

      Parameters

      • text: string

        The text of the input

      • placeholder: string = ""

        The placeholder of the input

      • defaultText: string = ...

      Returns this

    • Adds a slider to the form.

      Parameters

      • text: string

        The text of the slider

      • min: number

        The minimum value of the slider

      • max: number

        The maximum value of the slider

      • step: number = 1

        The step of the slider

      • defaultValue: number = min

        The default value of the slider

      Returns this

    • Adds a step slider to the form.

      Parameters

      • text: string

        The text of the step slider

      • steps: string[]

        The steps of the step slider

      • defaultIndex: number = 0

        The default index of the step slider

      Returns this

    • Adds a toggle switch to the form.

      Parameters

      • text: string

        The text of the toggle

      • defaultValue: boolean = false

        The default value of the toggle

      Returns this