my.prompt displays a dialog that prompts the user to enter text. The dialog includes a text input field, confirmation and cancel buttons, and returns the user's input through the success callback.
my.prompt({
title: 'Title',
message: 'Explain the current status and prompt the user solution. It is best not to exceed 3 lines.',
placeholder: 'Leave a message to a friend',
okButtonText: 'Confirm',
cancelButtonText: 'Cancel',
success: (result) => {
my.alert({
title: JSON.stringify(result),
});
},
});
| Property | Type | Required | Description |
|---|---|---|---|
title | String | No | Title of prompt box. |
message | String | Yes | Text of prompt box, which is "Enter contents here" by default. |
placeholder | String | No | Prompt text for the entry box. |
align | String | No | Message alignment. Valid values are: • left• center• rightThe default value is center for both iOS and Android. |
okButtonText | String | No | OK button text, which is OK by default. |
cancelButtonText | String | No | Cancel button text, which is Cancel by default. |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
The incoming parameter is of the Object type with the following attributes:
| Property | Type | Description |
|---|---|---|
ok | Boolean | Click OK to return true; click Cancel to return false. |
inputValue | String | When OK is true, return the user's entry. |
message parameter is requiredplaceholder to provide helpful hints about what should be enteredalign property controls message text alignment (left, center, or right)result.ok to determine if the user confirmed or cancelled:
true = OK button clicked, inputValue contains user inputfalse = Cancel button clickedmy.prompt({
title: 'Enter Name',
message: 'Please enter your full name',
placeholder: 'John Doe',
success: (result) => {
if (result.ok) {
console.log('User entered:', result.inputValue);
} else {
console.log('User cancelled');
}
},
});
my.prompt({
title: 'Feedback',
message: 'How can we improve?',
placeholder: 'Share your thoughts',
align: 'left',
okButtonText: 'Submit',
cancelButtonText: 'Skip',
success: (result) => {
if (result.ok && result.inputValue) {
// Process feedback
console.log('Feedback:', result.inputValue);
}
},
});
my.prompt({
title: 'Enter Email',
message: 'Please provide your email address',
placeholder: 'email@example.com',
success: (result) => {
if (result.ok) {
const email = result.inputValue;
if (email && email.includes('@')) {
console.log('Valid email:', email);
} else {
my.alert({
title: 'Invalid Email',
content: 'Please enter a valid email address',
});
}
}
},
});