Skip to content

Commit

Permalink
make select bookmark error a configurable callback
Browse files Browse the repository at this point in the history
  • Loading branch information
mejackreed committed Oct 25, 2018
1 parent df7e862 commit 9c1dca8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions app/assets/javascripts/blacklight/blacklight.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ Blacklight.onLoad(function () {
$("form.something").blCheckboxSubmit({
//cssClass is added to elements added, plus used for id base
cssClass: "toggle_my_kinda_form",
error: function() {
#optional callback
},
success: function(after_success_check_state) {
#optional callback
}
Expand Down Expand Up @@ -181,9 +184,9 @@ Blacklight.onLoad(function () {
type: form.attr('method').toUpperCase(),
data: form.serialize(),
error: function () {
alert('Error');
label.removeAttr('disabled');
checkbox.removeAttr('disabled');
options.error.call();
},
success: function (data, status, xhr) {
//if app isn't running at all, xhr annoyingly
Expand All @@ -195,9 +198,9 @@ Blacklight.onLoad(function () {
checkbox.removeAttr('disabled');
options.success.call(form, checked, xhr.responseJSON);
} else {
alert('Error');
label.removeAttr('disabled');
checkbox.removeAttr('disabled');
options.error.call();
}
}
});
Expand All @@ -212,6 +215,9 @@ Blacklight.onLoad(function () {
$.fn.blCheckboxSubmit.defaults = {
//cssClass is added to elements added, plus used for id base
cssClass: 'blCheckboxSubmit',
error: function () {
alert("Error");
},
success: function () {} //callback
};
})(jQuery);
Expand Down
10 changes: 8 additions & 2 deletions app/javascript/blacklight/checkbox_submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
$("form.something").blCheckboxSubmit({
//cssClass is added to elements added, plus used for id base
cssClass: "toggle_my_kinda_form",
error: function() {
#optional callback
},
success: function(after_success_check_state) {
#optional callback
}
Expand Down Expand Up @@ -91,9 +94,9 @@
type: form.attr('method').toUpperCase(),
data: form.serialize(),
error: function() {
alert('Error');
label.removeAttr('disabled');
checkbox.removeAttr('disabled');
options.error.call();
},
success: function(data, status, xhr) {
//if app isn't running at all, xhr annoyingly
Expand All @@ -105,9 +108,9 @@
checkbox.removeAttr('disabled');
options.success.call(form, checked, xhr.responseJSON);
} else {
alert('Error');
label.removeAttr('disabled');
checkbox.removeAttr('disabled');
options.error.call();
}
}
});
Expand All @@ -123,6 +126,9 @@
$.fn.blCheckboxSubmit.defaults = {
//cssClass is added to elements added, plus used for id base
cssClass: 'blCheckboxSubmit',
error: function() {
alert("Error");
},
success: function() {} //callback
};
})(jQuery);

0 comments on commit 9c1dca8

Please sign in to comment.