0

I've tried the various methods that normally work, but it seems SmartWizard is preventing these methods from working.

I need to disable the Finish button and change the text after it is clicked to prevent multiple submissions. No matter where I place the code, the screen does not change, the value of the button does not change, and the button does not disable.

I tried the typical click function...

$(".actionBar .buttonFinish").click(function(){
    $(".actionBar .buttonFinish").addClass("buttonDisabled");
    $(".actionBar .buttonFinish").text("Sending...");
});

I also tried using this as part of the final step validation and in the FinishCallback right before the ajax call. Nothing changes until AFTER the ajax call is completed and the ajax success runs.

UPDATE

Ok, this is for sure a timing issue. If I cause the ajax call to fail, the button disables and the text changes. I need to make sure these two things occur before moving on to the ajax call. So far, I tried this but it did not work:

$(".actionBar .buttonFinish").addClass("buttonDisabled").text("Sending...").ajax({
Connie DeCinko
  • 996
  • 5
  • 19
  • 39
  • Have you tried adding logging to things, to make sure the click handler is firing? – Whothehellisthat Sep 06 '16 at 17:27
  • 1
    Try using jQuery's `prop` function to set the `disabled` attribute true: `$(".actionBar .buttonFinish").prop( 'disabled', true );` assuming it is a ` – Stefan Dunn Sep 06 '16 at 17:28
  • try with $(".actionBar .buttonFinish").off('click') – gaetanoM Sep 06 '16 at 17:28
  • Use [.one()](http://api.jquery.com/one/) – Hector Barbossa Sep 06 '16 at 17:29
  • provide you html of the button finish – Irfan Anwar Sep 06 '16 at 17:47
  • I added a simple alert and there is a noticeable delay before it triggers. It seems like SmartWizard is grabbing the click event before any other event can fire. – Connie DeCinko Sep 06 '16 at 18:04
  • You say in a comment on another answer: _SmartWizard creates the "button" which is actually an anchor tag:_ `Purchase` — in that case all the advice about setting .prop (or .attr) disabled will not work. Try putting a blocking-pane with a high z-index in front of your page. Timing may still be an issue if smart-wizard is grabbing events. – Stephen P Sep 06 '16 at 22:55

5 Answers5

0
$(".actionBar .buttonFinish").click(function(){
   $(".actionBar .buttonFinish").attr('disabled', 'disabled');
   $(".actionBar .buttonFinish").text("Sending...");
});
Ankneema
  • 45
  • 5
0

you can add this at the end of the 'onclick' event to disable the button

$(this).prop( "disabled", true );

OR

$(this).attr("disabled", 'disabled');

you need to use the function 'prop' or 'attr' depending on the jquery version

zakaria35
  • 857
  • 1
  • 7
  • 12
  • No good. The link button does not disable and the text does not change until after the ajax method runs. SmartWizard seems to be running its function first. – Connie DeCinko Sep 06 '16 at 18:11
  • i don't know about the SmartWizard , but just add the disable code in the beginning of the click function or just before the ajax request – zakaria35 Sep 07 '16 at 08:18
0

Try this.

$(document).ready(function(){
  $(function(){
    $(".buttonFinish").on("click", function(){
      $(this).prop('disabled', true);
      $(this).val("Sending...");
    });
  });
});
input{
  display: block
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

<div>
  <form>
    <input type="text">
    <input type="text">
    <input class="buttonFinish" type="submit">
  </form>
</div>

UPDATE

Let me see if I understood you, you want to disable the button and the text before ajax call? You've tried with beforeSend?

$(document).ready(function(){
  $(function(){
    $("form").submit(function(e){
      e.preventDefault();
      
      $.ajax({
        beforeSend: function(){
          $(".buttonFinish").prop('disabled', true);
          $(".buttonFinish").val("Sending...");
        },
        complete: function(){
          // remove disabled and change the text
        },
      });
    });
  });
});
input{
  display: block
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

<div>
  <form>
    <input type="text">
    <input type="text">
    <input class="buttonFinish" type="submit">
  </form>
</div>
  • I need to disable the Finish button BEFORE the ajax call. Every attempt it appears the ajax runs prior to the button reflecting any change. So if the ajax call is slow or delayed or fails, the user can keep clicking over and over and submit multiple times. – Connie DeCinko Sep 06 '16 at 20:23
0

Since your .buttonFinish is a link, not actually a button, you can't disable it with .prop('disabled', true) — you may want to use a "blocking pane" instead.

Put a div at the very end of your page, I prefer just before the </body> tag, that contains nothing and is unseen, off the page and with no height and width.

    <div id="blocker"></div>
</body>

When the "button" is clicked then add a class on it that will make it show, using the full height/width of the page and with a high z-index so it is "in front" of everything else; it will get all the clicks which won't pass through to the controls underneath it as a lower z-index.
Your click handler would include $('blocker').addClass('blocking'); giving the resulting DOM ...

    <div id="blocker" class="blocking"></div>
</body>

Use CSS to style #blocker so it is unseen, then style #blocker.blocking so it blocks the rest of the page.

$('a.finished').click(function(e) {
  e.preventDefault();
  $('#blocker').addClass('blocking');
  // when ajax call finishes,
  // use $('#blocker').removeClass('blocking');
});
#blocker {
  position: fixed;
  top: -10px;
  left: -10px;
  height: 0;
  width: 0;
  z-index: -20;
  background-color: white;
}

#blocker.blocking {
  height: auto;
  width: auto;
  bottom: -10px;
  right: -10px;
  opacity: 0.6;
  z-index: 9000;
}
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.js"></script>
<div class="stuff">
  <p>This is stuff</p>
  <p>This is other stuff</p>
  <p>A <a href="#" class="finished">link</a> is in here.</p>
</div>
<div id="blocker"></div>
Stephen P
  • 14,422
  • 2
  • 43
  • 67
-1

Try this

<input type='button' id='btn' onclick='click_me()' value='click'>

  var disable = false;
  function click_me()
  {
    if(disable = 'false') {
      $(".actionBar .buttonFinish").addClass("buttonDisabled");
      $(".actionBar .buttonFinish").text("Sending...");
      disable = true;
    }
  }
Aks
  • 102
  • 8
  • Where is the actual disabling? Adding a class to make it look disabled is not the same as actually disabling it. – NoobishPro Sep 06 '16 at 17:46
  • SmartWizard creates the "button" which is actually an anchor tag: Purchase – Connie DeCinko Sep 06 '16 at 18:07
  • so what you can just replace onclick event with onfocus and add your method within if condition... and yu can also add onclick event an anchor tag if you dont pass url an anchor tag – Aks Sep 06 '16 at 18:14