I have this code, which is working quite well: <% form_tag '''', :method => ''GET'' do %> <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||''by_date'' %><b>By Date</b></p> <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] =''by_donor'' %><b>By Donor</b></p> <p><%= submit_tag "Choose" %><p> <% end %> <%= render( :partial => "orders" , :object => @orders ) %> (Inside of the _orders partial is where params[ :report ] is processed) But it''s ugly in that pressing "Choose" is redundant--I want the partial action to happen when the user simply selects the radio button. Is there any way to do this? Many TIA, Craig
Hi Craig, On Mon, 2009-09-21 at 19:56 -0700, Dudebot wrote:> I have this code, which is working quite well: > > <% form_tag '''', :method => ''GET'' do %> > <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||> ''by_date'' %><b>By Date</b></p> > <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] => ''by_donor'' %><b>By Donor</b></p> > <p><%= submit_tag "Choose" %><p> > <% end %> > > <%= render( :partial => "orders" , :object => @orders ) %> > (Inside of the _orders partial is where params[ :report ] is > processed) > > But it''s ugly in that pressing "Choose" is redundant--I want the > partial action to happen when the user simply selects the radio > button. Is there any way to do this?Assuming you''re OK with an Ajax request, check out the docs for observe_form. Best regards, Bill
Thanks, Bill! The docs for observe_form are sparse: "Observes the form with the DOM ID specified by form_id and calls a callback when its contents have changed. The default callback is an Ajax call. By default all fields of the observed field are sent as parameters with the Ajax call. The options for observe_form are the same as the options for observe_field. The JavaScript variable value available to the :with option is set to the serialized form by default." ... observe_field seems quite different... I''ve looked up various references on the web and played around without success. How would I use "observe_form" with my code? I get the feeling the answer is simple, and I''m just missing it... Many TIA, Craig On Sep 21, 10:09 pm, bill walton <bwalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi Craig, > > > > > > On Mon, 2009-09-21 at 19:56 -0700, Dudebot wrote: > > I have this code, which is working quite well: > > > <% form_tag '''', :method => ''GET'' do %> > > <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||> > ''by_date'' %><b>By Date</b></p> > > <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] => > ''by_donor'' %><b>By Donor</b></p> > > <p><%= submit_tag "Choose" %><p> > > <% end %> > > > <%= render( :partial => "orders" , :object => @orders ) %> > > (Inside of the _orders partial is where params[ :report ] is > > processed) > > > But it''s ugly in that pressing "Choose" is redundant--I want the > > partial action to happen when the user simply selects the radio > > button. Is there any way to do this? > > Assuming you''re OK with an Ajax request, check out the docs for > observe_form. > > Best regards, > Bill
This for example does not work: (index.html.erb) ... <% form_tag '''', { :id => ''myform'', :method => :get } do %> <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||''by_date'' %><b>By Date</b></p> <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] =''by_donor'' %><b>By Donor</b></p> <p><%= submit_tag "Choose" %><p> <% end %> <%= observe_form( ''myform'', :frequency => 1, :with => "report", :action => :index ) %> <%= render( :partial => "reports" ) %> ... Any ideas? Again, many TIA, Craig On Sep 21, 10:41 pm, Dudebot <craign...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks, Bill! The docs for observe_form are sparse: > > "Observes the form with the DOM ID specified by form_id and calls a > callback when its contents have changed. The default callback is an > Ajax call. By default all fields of the observed field are sent as > parameters with the Ajax call. > > The options for observe_form are the same as the options for > observe_field. The JavaScript variable value available to the :with > option is set to the serialized form by default." > > ... > > observe_field seems quite different... I''ve looked up various > references on the web and played around without success. How would I > use "observe_form" with my code? I get the feeling the answer is > simple, and I''m just missing it... > > Many TIA, > Craig > > On Sep 21, 10:09 pm, bill walton <bwalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi Craig, > > > On Mon, 2009-09-21 at 19:56 -0700, Dudebot wrote: > > > I have this code, which is working quite well: > > > > <% form_tag '''', :method => ''GET'' do %> > > > <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||> > > ''by_date'' %><b>By Date</b></p> > > > <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] => > > ''by_donor'' %><b>By Donor</b></p> > > > <p><%= submit_tag "Choose" %><p> > > > <% end %> > > > > <%= render( :partial => "orders" , :object => @orders ) %> > > > (Inside of the _orders partial is where params[ :report ] is > > > processed) > > > > But it''s ugly in that pressing "Choose" is redundant--I want the > > > partial action to happen when the user simply selects the radio > > > button. Is there any way to do this? > > > Assuming you''re OK with an Ajax request, check out the docs for > > observe_form. > > > Best regards, > > Bill
This gives you an ajax response. <%= radio_button_tag :report, ''by_date'', params[ :report ] ||''by_date'', :onclick => remote_function( :url=> { :controller => ''myforms'', :action => ''do'' } ) %> On Sep 21, 10:57 pm, Dudebot <craign...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This for example does not work: (index.html.erb) > ... > <% form_tag '''', { :id => ''myform'', :method => :get } do %> > <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||> ''by_date'' %><b>By Date</b></p> > <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] => ''by_donor'' %><b>By Donor</b></p> > <p><%= submit_tag "Choose" %><p> > <% end %> > > <%= observe_form( ''myform'', > :frequency => 1, > :with => "report", > :action => :index ) %> > > <%= render( :partial => "reports" ) %> > ... > > Any ideas? > Again, many TIA, > Craig > > On Sep 21, 10:41 pm, Dudebot <craign...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks, Bill! The docs for observe_form are sparse: > > > "Observes the form with the DOM ID specified by form_id and calls a > > callback when its contents have changed. The default callback is an > > Ajax call. By default all fields of the observed field are sent as > > parameters with the Ajax call. > > > The options for observe_form are the same as the options for > > observe_field. The JavaScript variable value available to the :with > > option is set to the serialized form by default." > > > ... > > > observe_field seems quite different... I''ve looked up various > > references on the web and played around without success. How would I > > use "observe_form" with my code? I get the feeling the answer is > > simple, and I''m just missing it... > > > Many TIA, > > Craig > > > On Sep 21, 10:09 pm, bill walton <bwalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi Craig, > > > > On Mon, 2009-09-21 at 19:56 -0700, Dudebot wrote: > > > > I have this code, which is working quite well: > > > > > <% form_tag '''', :method => ''GET'' do %> > > > > <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||> > > > ''by_date'' %><b>By Date</b></p> > > > > <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] => > > > ''by_donor'' %><b>By Donor</b></p> > > > > <p><%= submit_tag "Choose" %><p> > > > > <% end %> > > > > > <%= render( :partial => "orders" , :object => @orders ) %> > > > > (Inside of the _orders partial is where params[ :report ] is > > > > processed) > > > > > But it''s ugly in that pressing "Choose" is redundant--I want the > > > > partial action to happen when the user simply selects the radio > > > > button. Is there any way to do this? > > > > Assuming you''re OK with an Ajax request, check out the docs for > > > observe_form. > > > > Best regards, > > > Bill
Dudebot wrote:> I have this code, which is working quite well: > > <% form_tag '''', :method => ''GET'' do %> > <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||> ''by_date'' %><b>By Date</b></p> > <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] => ''by_donor'' %><b>By Donor</b></p> > <p><%= submit_tag "Choose" %><p> > <% end %> > > <%= render( :partial => "orders" , :object => @orders ) %> > (Inside of the _orders partial is where params[ :report ] is > processed) > > But it''s ugly in that pressing "Choose" is redundant--I want the > partial action to happen when the user simply selects the radio > button. Is there any way to do this?Sure. There''s no need for a form here as far as I can see -- just use links for the two options.> > Many TIA, > CraigBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Hi Craig, On Mon, 2009-09-21 at 20:57 -0700, Dudebot wrote:> This for example does not work: (index.html.erb)What, exactly, do you mean ''does not work''? Is the Ajax request not firing? Are there no params? If there are params, are they not named what you expect? If you''re going to use/debug Ajax, you need to be using Firefox and the Firebug plugin. You will be able to see all requests, params, and responses in the Firebug NET tab, and all Ajax requests, etc. in the Console tab. To help further, I''ll need to know what you''re seeing. Best regards, Bill
Or look up: http://railsbrain.com/api/rails-2.3.2/doc/index.html?a=M002477&name=observe_form http://railsbrain.com/api/rails-2.3.2/doc/index.html?a=M002476&name=observe_field -- Posted via http://www.ruby-forum.com/.
Dudebot wrote:> I have this code, which is working quite well: > > <% form_tag '''', :method => ''GET'' do %> > <p><%= radio_button_tag :report, ''by_date'', params[ :report ] ||> ''by_date'' %><b>By Date</b></p> > <p><%= radio_button_tag :report, ''by_donor'', params[ :report ] => ''by_donor'' %><b>By Donor</b></p> > <p><%= submit_tag "Choose" %><p> > <% end %> > > <%= render( :partial => "orders" , :object => @orders ) %> > (Inside of the _orders partial is where params[ :report ] is > processed) > > But it''s ugly in that pressing "Choose" is redundant--I want the > partial action to happen when the user simply selects the radio > button. Is there any way to do this? > > Many TIA, > CraigThe Radio button helper also has an onclick option so you can remote call a function when ever they click the button, or execute some javaScript. I have done this many times in my apps, for exmaple with gender: <% func1 = remote_function( :update => '''', :url => { :action => ''gender_female'', :id => @user.id}, :with => "''select='' + escape(value)" ) %> <% func2 = remote_function( :update => '''', :url => { :action => ''gender_male'', :id=> @user.id}, :with => "''select='' + escape(value)" ) %> <span id = "female">Male: <%= radio_button_tag( :gender, :male, @user.gender.to_s == "Male" ? true : false, :onclick => func2 )%></span> <span id = "male">Female: <%= radio_button_tag( :gender, :female, @user.gender.to_s == "Female" ? true : false, :onclick => func1 )%></span> -- Posted via http://www.ruby-forum.com/.