sud.showModal
Displays a modal dialog with confirmation, cancellation, and optional text input.
javascript
sud.showModal(object);Parameters
| Property | Type | Required | Description |
|---|---|---|---|
| title | string | No | Dialog title |
| content | string | No | Dialog message |
| showCancel | boolean | No | Whether to show the cancel button; set explicitly |
| cancelText | string | No | Cancel button label, up to 4 characters |
| cancelColor | string | No | Cancel button text color as a hexadecimal color string, such as #000000 |
| confirmText | string | No | Confirm button label, up to 4 characters |
| confirmColor | string | No | Confirm button text color as a hexadecimal color string, such as #576B95 |
| editable | boolean | No | Whether to show a text input field; set explicitly |
| placeholderText | string | No | Placeholder for the input field when editable: true |
| success | function | No | Called after the user clicks a button; see the fields below |
| fail | function | No | Called on failure |
| complete | function | No | Called after success or failure, with no arguments |
Success Callback Parameters
| Property | Type | Description |
|---|---|---|
| confirm | boolean | Whether the user clicked the confirm button |
| cancel | boolean | Whether the user clicked the cancel button |
| content | string | User input; use only when the input field is enabled |
Failure Callback Parameters
| Property | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error 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);
}
});