I'm trying to block multiple clicks. For buttons I got the solution, but for the links I still did not succeed. It has a solution that disables the link, but does not perform the action of the link. I tried using preventDefault, but I'm not sure that it would solve my problem.
Solution for buttons, works perfectly.
jQuery.fn.preventDoubleSubmit = function() {
jQuery(this).submit(function() {
console.log('preventDoubleSubmit..1');
//alert('preventDoubleSubmit..1');
if (this.beenSubmitted) {
console.log('preventDoubleSubmit..2');
//alert('preventDoubleSubmit..2');
return false;
} else {
console.log('preventDoubleSubmit..3');
//alert('preventDoubleSubmit..3');
this.beenSubmitted = true;
}
});
};
jQuery('form').preventDoubleSubmit();
Solution 1 for link, nothing happens when clicking.
$("a").click(function (e) {
console.log('Cliquei no link..1');
e.preventDefault();
var target = jQuery(this);
console.log("You clicked!", target.length);
target.trigger("click");
console.log('Cliquei no link..2');
});
Solution 2 for link, disables link but does not execute action
$("a").click(function () {
console.log('Vou desabilitar');
$(this).fadeTo("fast", .5).removeAttr("href");
return true;
});
HTML
<a href='<s:url action="Pedido!edit"><s:param name="id" value="id"/></s:url>'><strong>Editar</strong></a>
Just one more detail, the links are outside the form tag.