Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  184] [ 2]  / answers: 1 / hits: 25492  / 11 Years ago, thu, april 4, 2013, 12:00:00

I want to prevent multiple form submissions using angular.js. The question is related to this question.



When the user clicks on a form submit button the value / label of the submit button should change to loading.., status of the button will be set to disabled AND the submit event should be triggered in the normal way, leading to a submit call to the server. This way the user would see the following effect:




  1. Immediately: The submit button value changes to loading.. and gets disabled


  2. As soon as the server responds: user gets presented the result of the server request (whereas server responds are handled without angular intervention)




I created this plunk to show what I mean. My issue relates to this line: elm.attr('disabled',true); . This does not only disable the button, but also prevent to propagate the submit event. Thus I get a disabled button (desired result), but the form does not get submitted (undesired result).



You can see the changing behavior if you comment / uncomment this line : elm.attr('disabled',true);



Any idea how to change this?


More From » angularjs

 Answers
77

Try a $timeout (the angularjs function)



$timeout(function(){
elm.attr('disabled',true);
}, 0)

[#79127] Tuesday, April 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
casandra

Total Points: 334
Total Questions: 93
Total Answers: 104

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
casandra questions
Thu, Feb 25, 21, 00:00, 3 Years ago
Mon, Jul 6, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Tue, Sep 17, 19, 00:00, 5 Years ago
;