Atrox / sweetify-django

SweetAlert integration for Django
BSD 3-Clause "New" or "Revised" License
55 stars 21 forks source link

Handling event if ok button is clicked #9

Open ua4ever opened 5 years ago

ua4ever commented 5 years ago

How to do that ?

Atrox commented 5 years ago

Hey @ua4ever,

sweetify is more or less for informational one-time messages only. There is currently no (prebuilt) way to handle clicks.

I'm happy to accept a PR, if you find a good solution for this in sweetify.

PauMAVA commented 3 years ago

I think that with sweetalerts2 you can do the following:

Swal.fire(
    ...
).then(result) {
    if (result.isConfirmed) {

    } else if (result.isDenied) {

    }
    ...
}

The parameters of result are the following as described in the official docs:

isConfirmed | The "Confirm" button was clicked, the value will contain the result
isDenied | The "Deny" button was clicked, the value will be false. Alternatively, if there's an input in a popup, you can use returnInputValueOnDeny: true to return the input's value.
isDismissed | The "Cancel" button was clicked, the dismiss will be Swal.DismissReason.cancel
value | The value from the popup, possible values:                        
 * true for simple confirmed dialogs             
 * false for denied popups             
 * any value for popups with inputs
dismiss | The dismissal reason, see the Handling Dismissals section for details

Maybe we could try to port this to sweetify?