Skip to content

@minecraft/server-ui


@minecraft/server-ui / CustomForm

Class: CustomForm

Defined in: @minecraft/server-ui/index.d.ts:364

A customizable data driven (DDUI) form that lets you add buttons, labels, toggles, dropdowns, sliders, text fields, and more. The form layout is built by calling methods to add components before calling show(). Any Observable values bound to form components will automatically update the UI when their values change.

Constructors

Constructor

new CustomForm(player, title): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:378

Parameters

player

Player

The player to show this form to.

title

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The title text to display at the top of the form.

Returns

CustomForm

Remarks

Creates a new CustomForm for the specified player with the given title.

Throws

This function can throw errors.

minecraftserver.InvalidEntityError

Methods

button()

button(label, onClick, options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:401

Parameters

label

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The text label to display on the button.

onClick

() => void

A callback function that is invoked when the player clicks the button.

options?

ButtonOptions

Optional configuration for the button, such as a tooltip, disabled state, or visibility.

Returns

CustomForm

Remarks

Adds a clickable button to the form layout. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError


close()

close(): void

Defined in: @minecraft/server-ui/index.d.ts:422

Returns

void

Remarks

Closes the form if it is currently being shown to the player. Throws a FormVisibilityError if the form is not currently open.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

minecraftcommon.EngineError

FormVisibilityError

minecraftserver.InvalidEntityError


closeButton()

closeButton(): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:435

Returns

CustomForm

Remarks

Adds a close button to the form at the bottom and as an 'X' in the corner. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError


divider()

divider(options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:450

Parameters

options?

DividerOptions

Optional configuration for the divider, such as visibility.

Returns

CustomForm

Remarks

Adds a horizontal divider line to the form layout. Useful for visually separating sections of the form. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError


dropdown(label, value, items, options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:476

Parameters

label

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The text label displayed around the dropdown.

value

ObservableNumber

An ObservableNumber that holds the index of the currently selected item.

items

DropdownItemData[]

The list of items to display in the dropdown.

options?

DropdownOptions

Optional configuration for the dropdown, such as a description, disabled state, or visibility.

Returns

CustomForm

Remarks

Adds a dropdown selection control to the form layout. The current selection is tracked via an ObservableNumber and will update when the player changes the selection. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError

InvalidObservableError


header(text, options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:499

Parameters

text

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The header text to display.

options?

TextOptions

Optional configuration for the header, such as visibility.

Returns

CustomForm

Remarks

Adds a header text component to the form layout. Headers are displayed in a larger or bolder style than regular labels, and are suitable for section titles. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError


isShowing()

isShowing(): boolean

Defined in: @minecraft/server-ui/index.d.ts:508

Returns

boolean

Remarks

Returns true if the form is currently being shown to the player, false otherwise.

This function can't be called in restricted-execution mode.


label()

label(text, options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:524

Parameters

text

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The text to display in the label.

options?

TextOptions

Optional configuration for the label, such as visibility.

Returns

CustomForm

Remarks

Adds a read-only text label to the form layout. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError


show()

show(): Promise<DataDrivenScreenClosedReason>

Defined in: @minecraft/server-ui/index.d.ts:541

Returns

Promise<DataDrivenScreenClosedReason>

Remarks

Shows the form to the player. Returns a promise that resolves with a DataDrivenScreenClosedReason indicating how the form was closed.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

minecraftcommon.EngineError

FormVisibilityError

minecraftserver.InvalidEntityError


slider()

slider(label, value, min, max, options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:569

Parameters

label

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The text label displayed around the slider.

value

ObservableNumber

An ObservableNumber that holds the current value of the slider.

min

number | ObservableNumber

The minimum value of the slider range.

max

number | ObservableNumber

The maximum value of the slider range.

options?

SliderOptions

Optional configuration for the slider, such as step size, a description, disabled state, or visibility.

Returns

CustomForm

Remarks

Adds a numeric slider control to the form layout. The current value is tracked via an ObservableNumber and will update as the player moves the slider. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError

InvalidObservableError


spacer()

spacer(options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:590

Parameters

options?

SpacingOptions

Optional configuration for the spacer, such as visibility.

Returns

CustomForm

Remarks

Adds a vertical spacer component to the form layout. Useful for adding empty space between form components. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError


textField()

textField(label, text, options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:614

Parameters

label

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The text label displayed around the text field.

text

ObservableString

An ObservableString that holds the current text value of the input field.

options?

TextFieldOptions

Optional configuration for the text field, such as a description, disabled state, or visibility.

Returns

CustomForm

Remarks

Adds a text input field to the form layout. The current text value is tracked via an ObservableString and will update as the player types. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError

InvalidObservableError


toggle()

toggle(label, toggled, options?): CustomForm

Defined in: @minecraft/server-ui/index.d.ts:642

Parameters

label

string | ObservableString | ObservableUIRawMessage | UIRawMessage

The text label displayed next to the toggle.

toggled

ObservableBoolean

An ObservableBoolean that holds the current on/off state of the toggle.

options?

ToggleOptions

Optional configuration for the toggle, such as a description, disabled state, or visibility.

Returns

CustomForm

Remarks

Adds a toggle (on/off switch) control to the form layout. The current state is tracked via an ObservableBoolean and will update when the player toggles it. Returns the form instance to allow method chaining.

This function can't be called in restricted-execution mode.

Throws

This function can throw errors.

InvalidFormModificationError

InvalidObservableError