disable form ketika submit

ini sih snippet seingetnya aja, biasanya kalo di halaman web abis submit takutnya ke klik dua kali maka ditahan pake javascript ini

<script type="text/javascript">
window.onload = function() {
  $( document ).ready(function() {
      // console.log( "ready! di header" );

      var $div = $('body');
      var lod = false;

      var observer = new MutationObserver(function(mutations) {
          mutations.forEach(function(mutation) {
              if (mutation.attributeName === "class") {
                var attributeValue = $(mutation.target).prop(mutation.attributeName);
                  // console.log("Class attribute changed to:", attributeValue);

                  if(attributeValue.indexOf("loading")>0) {
                    // console.log("loading start");
                    lod = true;
                    $('div *').prop('disabled',true);
                  } else {
                    if(lod) {
                      // console.log("loading end");
                      lod = false;
                      $('div *').prop('disabled',false);
                    }
                  }
                  
              }
          });
      });

      observer.observe($div[0],  {
          attributes: true
      });
  });  

}
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *