-2

In a few places in my app, users sometimes accidentally submit a form more than once. I'd like to disallow this. I'm tempted to simply put this app-wide:

$("form").submit ->
  TextInput.disable_submit $(this)

Is this the most comprehensive and safe way to go about this?

John Bachir
  • 22,495
  • 29
  • 154
  • 227
  • that question involves additional questions/problems about the status indicator... – John Bachir Feb 28 '14 at 02:24
  • the accepted answer even involves server-side code... clearly that is a much more complicated and different scenario – John Bachir Feb 28 '14 at 02:25
  • 1
    Look to the right. This has been asked a lot in various forms. Review them and you'll have a good idea about how to go about this. Otherwise this question is too broad. – John Conde Feb 28 '14 at 02:26
  • i don't see anything in the right column which answers my qusetion – John Bachir Feb 28 '14 at 02:29
  • 1
    You've earned a downvote for lack of effort. This is a common question. It's definitely answered on this site and can easily be found with a Google search. – John Conde Feb 28 '14 at 02:30

1 Answers1

2

Simply use:

$('#form-id').submit(function(event){

    event.preventDefault();
    $('#your-submit-btn-id').prop("disabled", true);

    //Insert validation or what you need to do

)};

This will disable your button once it has been clicked once. You can validate and re-enable if needed using this:

 $('#your-submit-btn-id').prop("disabled", false);
larrylampco
  • 597
  • 1
  • 9
  • 33