wire:confirm

In CBWIRE, wire:confirm prompts users for confirmation before executing potentially irreversible actions, such as deletions or updates. This feature enhances the security and user-friendliness of your application by ensuring that actions are intended.

Example: Confirming Subscription Cancellation

Here’s an example of how to implement wire:confirm for a "Cancel Subscription" button:

component extends="cbwire.models.Component" {

    function cancelSubscription() {
        // Logic to cancel the subscription
    }

    function renderIt() {
        return template( "wires.cancelSubscription" );
    }
}

In your cancelSubscription view file (wires/cancelSubscription.cfm):

<button type="button" wire:click="cancelSubscription" wire:confirm="Are you sure you want to cancel your subscription?">
    Cancel Subscription
</button>

In this setup, when the user clicks "Cancel Subscription," CBWIRE triggers a confirmation dialog. If the user confirms the action by pressing "OK," the subscription cancellation process will proceed. If they cancel, no action will be taken.

Prompting Users for Specific Input

CBWIRE supports prompting the user to enter a specific string for actions requiring an extra layer of confirmation.

Suppose you want the user to confirm their intention to deactivate their account by typing a specific phrase:

 component extends="cbwire.models.Component" {

    function deactivateAccount() {
        // Logic to deactivate the account
    }

    function renderIt() {
        return template( "wires.deactivateAccount" );
    }
}

In your deactivateAccount view file (wires/deactivateAccount.cfm):

<button type="button"
        wire:click="deactivateAccount"
        wire:confirm.prompt="Please confirm deactivation by typing 'DEACTIVATE' below|DEACTIVATE">
    Deactivate Account
</button>

With this configuration, when users press "Deactivate Account," they will be prompted to type "DEACTIVATE" into the input field. The action will only be executed if the input matches exactly, adding security to sensitive operations.

Last updated