0

I have all kinds of buttons around the app. buttons that I want to have a spinner next to it ( to notify that something is going on ) - I add a specific class ajax_wait.

I catch them with $('.ajax_wait')

Problem is, when the selector catch buttons inside forms - the form will no longer submit. BUT, this behavior happens only in Chrome - in Firefox it will still submit ..

This is caused because of the .prop('disabled', true) - if I remove it - it works fine.

But I'm trying to find a solution still to make it work globally ( w/o binding submits etc .. ) as I'm not sure what else it will catch when the app grows.

Tried to place return true, tried many thing, nothing seems to work.

$(function() {
  $('.ajax_wait').on('click', function() {
    $(this)
      .prop('disabled', true)
      .attr('data-text', "Save")
      .html("saving please wait");
  })
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Click this button first - see the JavaScript change: <br />
<button type="button" class="ajax_wait"> Generic button </button>

<br />
<br />
<form method='GET'>
  Click this button second in Chrome - it doesn't work <br /> Click this button second in Firefox - it works ?! <br />

  <button type="submit" class="ajax_wait"> Save </button>
</form>

Codepen: https://codepen.io/arlevi/pen/PoqdgEZ

As you can see, the buttons that I bind are not always inside a form, sometimes they do other stuff - but generally across the app every "ajax_wait" will place a msg for waiting ...

How can I make the form to submit together with the .prop('disabled', true) ?

Ricky Levi
  • 7,298
  • 1
  • 57
  • 65

0 Answers0