Class: ModalFormData
Used to create a fully customizable pop-up form for a player.
Example
import { Player } from '@minecraft/server';
import { ModalFormData } from '@minecraft/server-ui';
function showExampleModal(player: Player) {
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(player)
.then(formData => {
player.sendMessage(`Modal form results: ${JSON.stringify(formData.formValues, undefined, 2)}`);
})
.catch((error: Error) => {
player.sendMessage('Failed to show form: ' + error);
return -1;
});
}
Constructors
new ModalFormData()
new ModalFormData():
ModalFormData
Returns
Methods
dropdown()
dropdown(
label
,options
,defaultValueIndex
?):ModalFormData
Parameters
Parameter | Type |
---|---|
label | string | RawMessage |
options | (string | RawMessage )[] |
defaultValueIndex ? | number |
Returns
Remarks
Adds a dropdown with choices to the form.
show()
show(
player
):Promise ↗️
<ModalFormResponse
>
Parameters
Parameter | Type | Description |
---|---|---|
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 read-only mode.
Throws
This function can throw errors.
slider()
slider(
label
,minimumValue
,maximumValue
,valueStep
,defaultValue
?):ModalFormData
Parameters
Parameter | Type |
---|---|
label | string | RawMessage |
minimumValue | number |
maximumValue | number |
valueStep | number |
defaultValue ? | number |
Returns
Remarks
Adds a numeric slider to the form.
submitButton()
Beta
submitButton(
submitButtonText
):ModalFormData
Parameters
Parameter | Type |
---|---|
submitButtonText | string | RawMessage |
Returns
textField()
textField(
label
,placeholderText
,defaultValue
?):ModalFormData
Parameters
Parameter | Type |
---|---|
label | string | RawMessage |
placeholderText | string | RawMessage |
defaultValue ? | string | RawMessage |
Returns
Remarks
Adds a textbox to the form.
title()
title(
titleText
):ModalFormData
Parameters
Parameter | Type |
---|---|
titleText | string | RawMessage |
Returns
Remarks
This builder method sets the title for the modal dialog.
toggle()
toggle(
label
,defaultValue
?):ModalFormData
Parameters
Parameter | Type |
---|---|
label | string | RawMessage |
defaultValue ? | boolean |
Returns
Remarks
Adds a toggle checkbox button to the form.