Skip to content

@minecraft/server-ui


@minecraft/server-ui / ModalFormData

Class: ModalFormData

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

Used to create a fully customizable pop-up form for a player.

Example

showBasicModalForm.ts

typescript
import { world, DimensionLocation } from '@minecraft/server';
import { ModalFormData } from '@minecraft/server-ui';

function showBasicModalForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) {
  const players = world.getPlayers();

  const modalForm = new ModalFormData().title('Example Modal Controls for §o§7ModalFormData§r');

  modalForm.toggle('Toggle w/o default');
  modalForm.toggle('Toggle w/ default', true);

  modalForm.slider('Slider w/o default', 0, 50, 5);
  modalForm.slider('Slider w/ default', 0, 50, 5, 30);

  modalForm.dropdown('Dropdown w/o default', ['option 1', 'option 2', 'option 3']);
  modalForm.dropdown('Dropdown w/ default', ['option 1', 'option 2', 'option 3'], 2);

  modalForm.textField('Input w/o default', 'type text here');
  modalForm.textField('Input w/ default', 'type text here', 'this is default');

  modalForm
    .show(players[0])
    .then(formData => {
      players[0].sendMessage(`Modal form results: ${JSON.stringify(formData.formValues, undefined, 2)}`);
    })
    .catch((error: Error) => {
      log('Failed to show form: ' + error);
      return -1;
    });
}

Constructors

Constructor

new ModalFormData(): ModalFormData

Returns

ModalFormData

Methods

divider()

divider(): ModalFormData

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

Returns

ModalFormData

Remarks

Adds a section divider to the form.


dropdown(label, items, dropdownOptions?): ModalFormData

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

Parameters

label

string | RawMessage

The label to display for the dropdown.

items

(string | RawMessage)[]

The selectable items for the dropdown.

ModalFormDataDropdownOptions

The optional additional values for the dropdown creation.

Returns

ModalFormData

Remarks

Adds a dropdown with choices to the form.


header(text): ModalFormData

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

Parameters

text

string | RawMessage

Text to display.

Returns

ModalFormData

Remarks

Adds a header to the form.


label()

label(text): ModalFormData

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

Parameters

text

string | RawMessage

Text to display.

Returns

ModalFormData

Remarks

Adds a label to the form.


show()

show(player): Promise<ModalFormResponse>

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

Parameters

player

Player

Player to show this dialog to.

Returns

Promise<ModalFormResponse>

Remarks

Creates and shows this modal popup form. Returns asynchronously when the player confirms or cancels the dialog.

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

Throws

This function can throw errors.

minecraftcommon.EngineError

minecraftserver.InvalidEntityError

minecraftserver.RawMessageError


slider()

slider(label, minimumValue, maximumValue, sliderOptions?): ModalFormData

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

Parameters

label

string | RawMessage

The label to display for the slider.

minimumValue

number

The minimum selectable possible value.

maximumValue

number

The maximum selectable possible value.

sliderOptions?

ModalFormDataSliderOptions

The optional additional values for the slider creation.

Returns

ModalFormData

Remarks

Adds a numeric slider to the form.


submitButton()

submitButton(submitButtonText): ModalFormData

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

Parameters

submitButtonText

string | RawMessage

Returns

ModalFormData


textField()

textField(label, placeholderText, textFieldOptions?): ModalFormData

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

Parameters

label

string | RawMessage

The label to display for the textfield.

placeholderText

string | RawMessage

The place holder text to display.

textFieldOptions?

ModalFormDataTextFieldOptions

The optional additional values for the textfield creation.

Returns

ModalFormData

Remarks

Adds a textbox to the form.


title()

title(titleText): ModalFormData

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

Parameters

titleText

string | RawMessage

Returns

ModalFormData

Remarks

This builder method sets the title for the modal dialog.


toggle()

toggle(label, toggleOptions?): ModalFormData

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

Parameters

label

string | RawMessage

The label to display for the toggle.

toggleOptions?

ModalFormDataToggleOptions

The optional additional values for the toggle creation.

Returns

ModalFormData

Remarks

Adds a toggle checkbox button to the form.