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.
×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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.