EasyUI Forum
May 21, 2024, 08:48:28 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Globally Prevent Double Click on Button  (Read 6287 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« 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.
Logged

-- Licensed User --
proceno72
Newbie
*
Posts: 39



View Profile
« Reply #1 on: July 26, 2016, 12:00:48 AM »

Yes, it could be very useful for me too. Any help would be appreciated
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #2 on: July 28, 2016, 09:25:48 PM »

Hello;

Any solutions for this ??
Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 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>
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!