I am trying to create a jQuery function to check whether a Cancel or Remove button was pressed on a facebox dialog, however I am not quite sure how to go about it.
Right now, I have:
// Confirm and remove group members
$("[id^='removeGroupMember_']").click(function () {
confirmDialog('Removal', 'Are you sure you want to remove this person from the group?');
// I need to check the results of the confirm dialog prior
// to calling the code below to remove the actual rows
$(this).parent().slideUp("fast", function () {
$(this).remove();
updateGroupRows();
});
return false;
});
Where confirmDialog
is:
function confirmDialog(action, message) {
$.facebox('<h3 class="confirmHeader light tb">Confirm ' + action + '</h3><div class="confirmContent"><p>' + message + '</p><a href="#" id="dialogConfirmAction" class="ras small red button right">' + action + '</a><a href="#" id="dialogConfirmCancel" class="ras small gray button right">Cancel</a></div>');
};
Right now, I have two functions for when those buttons are pressed, but I'm not sure how to check their result and feed that back in so I can decide whether or not to delete the associated row:
$('#dialogConfirmAction').live('click', function() {
console.log('Yep... they dun clicked it.');
return true;
});
$('#dialogConfirmCancel').live('click', function() {
$.facebox.close();
return true;
});
Any guidance you can provide is greatly appreciated!
What you want to do is change your
confirmDialog
function to be like so:You can then pass what you want to happen "on action" by passing a function to the
confirmDialog
function. This would make your other code look like this:And you can extend that by adding another variable to say what to do on cancel.