Skip to content

Instantly share code, notes, and snippets.

@dakshhmehta
Created September 1, 2020 06:44
Show Gist options
  • Save dakshhmehta/04468ae9b762fdaa31e59fb8740ddbe0 to your computer and use it in GitHub Desktop.
Save dakshhmehta/04468ae9b762fdaa31e59fb8740ddbe0 to your computer and use it in GitHub Desktop.
Actionable Select
$(".actionable-select").change(function (e) {
e.preventDefault();
var href = $(this).data('url');
var method = $(this).data('method') || 'GET';
var isClickable = $(e.target).is(":disabled");
var _data = {};
if (method == 'PUT' || method == 'POST') {
_data[$(this).attr("name")] = $(this).val();
}
console.log('Triggering actionable select request', method, _data)
if (isClickable == false) {
$.ajax({
method: method,
data: _data,
url: href,
success: function (res) {
$(e.target).prop('disabled', false);
if (res.error == true) {
app.$notify.error({ title: 'Error!', message: res.message });
return false;
}
app.$notify.success({ message: res.message });
if (res.changeText != undefined) {
$(e.target).html(res.changeText);
}
if (res.disableBtn != undefined) {
$(e.target).data('clickable', res.disableBtn);
if (res.disableBtn == 1) {
$(e.target).prop('disabled', true);
$(e.target).attr("disabled", "disabled");
}
}
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment