UI APIs

confirm

Display a confirmation dialog with two action buttons for user decision.

Overview

my.confirm displays a confirmation box with two buttons, allowing users to confirm or cancel an action. The success callback receives a result indicating which button was pressed.

Sample Code

my.confirm({
  title: 'Tips',
  content: 'Do you want to check the courier number: 1234567890?',
  confirmButtonText: 'Inquire now',
  cancelButtonText: 'Not needed',
  success: (result) => {
    my.alert({
      title: `${result.confirm}`,
    });
  },
});

Parameters

PropertyTypeRequiredDescription
titleStringNoTitle of the confirm box.
contentStringNoContent of the confirm box.
confirmButtonTextStringNoOK button text, which is "OK" by default.
cancelButtonTextStringNoCancel button text, which is "Cancel" by default.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

PropertyTypeDescription
confirmBooleanClick Confirm to return true; click Cancel to return false.

Usage Notes

  • The confirm dialog is modal - it blocks interaction until the user makes a choice
  • Use result.confirm to determine which button was pressed:
    • true = Confirm button clicked
    • false = Cancel button clicked
  • Default button texts are "OK" and "Cancel" if not customized

Examples

Basic Confirmation

my.confirm({
  title: 'Delete Item',
  content: 'Are you sure you want to delete this item?',
  success: (result) => {
    if (result.confirm) {
      console.log('User confirmed deletion');
      // Proceed with deletion
    } else {
      console.log('User cancelled');
    }
  },
});

Custom Button Labels

my.confirm({
  title: 'Leave Page',
  content: 'You have unsaved changes. Do you want to leave?',
  confirmButtonText: 'Leave',
  cancelButtonText: 'Stay',
  success: (result) => {
    if (result.confirm) {
      // Navigate away
    }
  },
});