Tomasz Romanowski
2010-Aug-20 21:36 UTC
How to disable button generated by submit_to_remote?
I got a submit_to_remote button that I''d like to show as disabled on a certain condition. I''d assume the usual :disabled => true would do but I have not been able to. Comparing page source shows that for example: <%= submit_to_remote "add", "Add", :url => { :action => "add_groups" }, :update => ''divgrouptable'', :disabled => true %> the ":disabled = true" statement has no effect on the generated html. Also tried "{ :disabled => true }" and a few others. I went as far as writing on-load hook and disabling the buttons in the java script as shown below but sounds like a lot of effort to achieve this. How could I make this less "obtrusive"? function disable_buttons() { <% if @readonly %> document.getElementsByName(''add'')[0].disabled = 1 document.getElementsByName(''remove'')[0].disabled = 1 <% end %> } </script> <body onload="javascript:onloadd()"> <original form goes here.......> </body> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
These 2 versions will disable the button: <%= submit_to_remote "add", "Add", :url => { :action => "add_groups" }, :html => {:update => ''divgrouptable'', :disabled => true} %> <%= submit_to_remote "add", "Add", :url => { :action => "add_groups" }, :update => ''divgrouptable'', :html => {:disabled => true} %> I have never used the submit_to_remote before and I''m not too familiar with the Ajax helpers so I''m not sure if :update has to be inside the :html hash or not. In any case, in the docs the example reads like this: :update => { :success => "succeed", :failure => "fail" } I don''t know if your :update stuff will work as it is. On Aug 20, 5:36 pm, Tomasz Romanowski <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I got a submit_to_remote button that I''d like to show as disabled on a > certain condition. I''d assume the usual :disabled => true would do but I > have not been able to. Comparing page source shows that for example: > > <%= submit_to_remote "add", "Add", :url => { :action => "add_groups" }, > :update => ''divgrouptable'', :disabled => true %> > > the ":disabled = true" statement has no effect on the generated html. > Also tried "{ :disabled => true }" and a few others. > > I went as far as writing on-load hook and disabling the buttons in the > java script as shown below but sounds like a lot of effort to achieve > this. How could I make this less "obtrusive"? > > function disable_buttons() > { > <% if @readonly %> > document.getElementsByName(''add'')[0].disabled = 1 > document.getElementsByName(''remove'')[0].disabled = 1 > <% end %> > > } > > </script> > > <body onload="javascript:onloadd()"> > > <original form goes here.......> > > </body> > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tomasz Romanowski
2010-Aug-26 13:38 UTC
Re: How to disable button generated by submit_to_remote?
Both examples work, thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.