EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on July 25, 2016, 08:58:35 PM



Title: Globally Prevent Double Click on Button
Post by: devnull on July 25, 2016, 08:58:35 PM
Just discovered that some users are double-clicking buttons resulting in duplicate records being added.

Is it possible to GLOBALLY extend the linkbutton to prevent double clicks by using either a delay or a true/false parameter i.e.:

Code:
$('#mybut').linkbutton({
  doubleclick: false
  repeatMsec: 1000
})

I would like to add this globally rather than adding code to every button individually.


Title: Re: Globally Prevent Double Click on Button
Post by: proceno72 on July 26, 2016, 12:00:48 AM
Yes, it could be very useful for me too. Any help would be appreciated


Title: Re: Globally Prevent Double Click on Button
Post by: devnull on July 28, 2016, 09:25:48 PM
Hello;

Any solutions for this ??


Title: Re: Globally Prevent Double Click on Button
Post by: stworthy on July 29, 2016, 06:50:34 AM
Here is the extended method 'singleClick' that can avoid double click on it.
Code:
<script type="text/javascript">
(function($){
function setClick(target){
var clickHandler = function(e){
var opts = $(this).linkbutton('options');
if (!opts.disabled){
if (opts.toggle){
if (opts.selected){
$(this).linkbutton('unselect');
} else {
$(this).linkbutton('select');
}
}
opts.onClick.call(this);

$(target).unbind('click.linkbutton');
$(target).linkbutton('disable');
$(target).removeClass('l-btn-disabled l-btn-plain-disabled');
setTimeout(function(){
$(target).linkbutton('enable');
$(target).unbind('click.linkbutton').bind('click.linkbutton', clickHandler);
}, 1000);
}
};
$(target).unbind('click.linkbutton').bind('click.linkbutton', clickHandler);
}
$.extend($.fn.linkbutton.methods, {
singleClick: function(jq){
return jq.each(function(){
setClick(this);
});
}
})
})(jQuery);
$(function(){
$('#btn-add').linkbutton('singleClick');
});
</script>