I have a toggle where I need to disable the remote link while the server sends the true/false data to the database. I will then re-enable the link on ajax:success.
I cant use e.preventDefault() on a rails remote link
I want to be able to do something like this:
$('body').on('click', '.toggle_link', function(){
//disable remote link
})
$('body').on('ajax:success', '.toggle_link', function(){
//enable remote link
})
Is there a best practice for accomplishing this?
You can also wire into the ajax:beforeSend event in ujs.
$(document).on('ajax:beforeSend', 'a[data-remote=true]', function(event, xhr, status, error) {
// stash the link
// remove the href
});
I used a varient of this to prevent data-remote links from running when they had a css class of 'disabled'
$(document).on('ajax:beforeSend', 'a.disabled[data-remote=true]', function(event, xhr, status, error) {
event.preventDefault();
event.stopImmediatePropagation();
return false;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With