Hey all i am trying to add a second button to this Apprise V2 JS code. However, i can not seem to get the correct click event for whichever one was clicked on.
Adding the buttons part of the code:
// Add buttons
$.each(settings.buttons, function(i, button) {
if(button) {
button.id = "Accept";
button.text = "Accept";
var $_button = $('<button id="apprise-btn-' + button.id + '">').append(button.text);
button.className = "green";
$_button.addClass(button.className);
$_buttons.append($_button);
$_button.on("click", function() {
var response = {
clicked: button,
};
button.action(response);
});
// Deny button
button.id = "Deny";
button.text = "Deny";
var $_button = $('<button id="apprise-btn-' + button.id + '">').append(button.text);
button.className = "red";
$_button.addClass(button.className);
$_buttons.append($_button);
$_button.on("click", function() {
var response = {
clicked: button,
};
button.action(response);
});
}
});
And this is the part of the code that fires the box:
$(function() {
$('#custom-tryit').on("click", function() {
var $response = $('custom-response');
var options = {
buttons: {
confirm: {
text: 'Accept',
className: 'blue',
action: function(e) {
console.log(this.id);
if (this.id == 'Deny') {
//Goto home page
console.log('home page');
} else {
//carry on
console.log('carry on');
}
Apprise('close');
}
},
},
input: false
};
Apprise('This is just a test here', options);
});
});
The original code didn't seem to have an option for more than 1 button... The output seems to be outputting both values instead of just what was clicked on (console.log(this.id);):
Deny
home page
Any help would be great!
The JSFIDDLE