Activate-Deactivate submit button in a form
I made a registration form using backbone.js, CoffeeScript and jquery.
I am trying to disable the submit button after 1 click (so that it doesn't fire events again and again) , i also want that button get active again when i fill fields of my form.. Thanks for your t开发者_运维技巧ime.In your code that runs the event (hopefully in the events delegate routine of your view) all you have to do is tell JQuery to disable the button
$("#btnSubmit").attr("disabled", true);
Then when you need to re-enable it
$("#btnSubmit").removeAttr("disabled");
Just call the appropriate calls when required.
seems there is no enable/disable property. maybe you could use the “silent” option to keep the “change” event from triggering?
or just create a validation routine and call it from the event i.e.
(pseudo code)
BUTTON EVENT FIRED IF IsValid() then 'do something else 'do something else end if func IsValid() as boolean ' check to see if the form is ready to submit i.e. required fields are valid
Thanks alot @Bryan and @max ..
I have done it as :
enable_button: ->
$("#my_button").attr("disabled", false).removeClass('disabled')
I am also changing the color of button on enable/disable.
精彩评论