Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to find out which button was pressed on a Dialog2?

Dirk Eyfrig March 14, 2022

I've implemented the last example (A warning message) provided on the Dialog2 documentation page.

So far, so nice.

But an action should only happen when the user pressed the "Delete the thing" button, but not when pressing the "Cancel" button.

But how do I find out which button a user pressed?

1 answer

1 accepted

1 vote
Answer accepted
Dirk Eyfrig March 14, 2022

OK, I found the solution myself.

From the example, you have to replace 

AJS.$(document).on("click", "#demo-warning-dialog button", function (e) {
e.preventDefault();
AJS.dialog2("#demo-warning-dialog").hide();
})

by separate handlers for the two buttons

AJS.$(document).on('click', '#warning-dialog-confirm', function (e) {
e.preventDefault()
AJS.dialog2('#demo-warning-dialog').hide()
// code that needs to be run when action is confirmed
alert('action confirmed')
})

AJS.$(document).on('click', '#warning-dialog-cancel', function (e) {
e.preventDefault()
AJS.dialog2('#demo-warning-dialog').hide()
})

 

Or is there a more elegant solution?

If not, the above code might be added to the documentation page.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Upcoming Confluence Events