Skip to content

sud.showModal ​

Displays a modal dialog with confirmation, cancellation, and optional text input.

javascript
sud.showModal(object);

Parameters ​

PropertyTypeRequiredDescription
titlestringNoDialog title
contentstringNoDialog message
showCancelbooleanNoWhether to show the cancel button; set explicitly
cancelTextstringNoCancel button label, up to 4 characters
cancelColorstringNoCancel button text color as a hexadecimal color string, such as #000000
confirmTextstringNoConfirm button label, up to 4 characters
confirmColorstringNoConfirm button text color as a hexadecimal color string, such as #576B95
editablebooleanNoWhether to show a text input field; set explicitly
placeholderTextstringNoPlaceholder for the input field when editable: true
successfunctionNoCalled after the user clicks a button; see the fields below
failfunctionNoCalled on failure
completefunctionNoCalled after success or failure, with no arguments

Success Callback Parameters ​

PropertyTypeDescription
confirmbooleanWhether the user clicked the confirm button
cancelbooleanWhether the user clicked the cancel button
contentstringUser input; use only when the input field is enabled

Failure Callback Parameters ​

PropertyTypeDescription
errCodenumberError code
errMsgstringError description

Usage Notes ​

Confirm that the target app supports this UI feature before using it. Clicking the cancel button also invokes success; check confirm or cancel to identify the user's choice. To request text input, set editable: true and validate content after confirmation.

Example ​

javascript
sud.showModal({
  title: 'Leave game',
  content: 'Leave the current round?',
  showCancel: true,
  cancelText: 'Stay',
  cancelColor: '#000000',
  confirmText: 'Quit',
  confirmColor: '#576B95',
  editable: false,
  success(result) {
    if (result.confirm) {
      console.log('User confirmed leaving');
    } else if (result.cancel) {
      console.log('User canceled leaving');
    }
  },
  fail(error) {
    console.error('Failed to show dialog', error.errCode, error.errMsg);
  }
});