How to do double-click prevention in JSF

前端 未结 7 1097
生来不讨喜
生来不讨喜 2020-11-29 02:56

We have a few search pages that run against a lot of data and take a while to complete. When a user clicks on the search button, we\'d like to not allow them to submit the s

7条回答
  •  眼角桃花
    2020-11-29 03:17

    i came upon this question, having the same problem. The solution did not work for me - after a brief look at primefaces.js i guess they do not use jsf.ajax there anymore.

    so i had to work something out myself and here is my solution, for people who also can not use the one in the answer by BalusC:

    // we override the default send function of
    // primeFaces here, so we can disable a button after a click
    // and enable it again after     
    
    var primeFacesOriginalSendFunction = PrimeFaces.ajax.AjaxUtils.send;
    
    PrimeFaces.ajax.AjaxUtils.send = function(cfg){    
      var callSource = '';
    
      // if not string, the caller is a process - in this case we do not interfere
    
      if(typeof(cfg.source) == 'string') {
    
        callSource = jQuery('#' + cfg.source);
        callSource.attr('disabled', 'disabled');
    
      }
    
    
    
      // in each case call original send
      primeFacesOriginalSendFunction(cfg);
    
      // if we disabled the button - enable it again
      if(callSource != '') {
    
        callSource.attr('disabled', 'enabled');
    
      }
    
    };
    

提交回复
热议问题