Topic: radio_button_tag and observe_field question

I have 2 radio buttons, and I want them to toggle the display between current year and all year.  I have successfully used observe_fields for selection pulldowns, and use AJAX to update information as necessary.  However, I'm having some trouble with the radio buttons and the observe_field tag. 

<%= radio_button_tag :radio, :current_year, :checked => true %>Current Year /
<%= radio_button_tag :radio, :all_years %>All Years

%= observe_field "radio[current_year]", :url => { :action => 'current_year' }, :with => "radio[current_year]" %>

Do I need an observe_field for the "all_years" button as well?  Because when I select one, the other one automatically de-selects.  If anyone knows, or could help me out, I'd appreciate it.  Thanks.

Re: radio_button_tag and observe_field question

daniel_l wrote:

Because when I select one, the other one automatically de-selects.  If anyone knows, or could help me out, I'd appreciate it.  Thanks.

Isn't that the point of radio buttons? (Only one can be selected at a time... "Radio buttons got their name from the physical buttons used on radios to select preset stations - when one of the buttons was pressed, it would pop out when another button was pushed in." - wikipedia)

Re: radio_button_tag and observe_field question

The problem I'm trying to accomplish is when you select a single radio button, I want the form to automatically update a certain portion of the page with AJAX.  Sorry about the confusion; I undertand what a radio button is smile.  I was saying that they seem to be automatically tied together already, in that when I select one, it already de-selects the other one.  So the problem I'm having is when you select a radio button, how do you cause it to make an AJAX request to update portions of the screen?

Re: radio_button_tag and observe_field question

I am having a similar problem.

The code I am using is as follows:

#----- index.rhtml
...
<%= form_remote_tag %>
<%= radio_button_tag "button", "1", false, :id=>'button1' %>
<%= radio_button_tag "button", "2", false, :id=>'button2' %>
<%= radio_button_tag "button", "3", false, :id=>'button3' %>

<%= observe_field 'button1', :update=>'display', :url=>{:action=>'update_debugger'}, :with => "button_id", :on => 'changed' %>
<%= observe_field 'button2', :update=>'display', :url=>{:action=>'update_debugger'}, :with => "button_id", :on => 'changed' %>
<%= observe_field 'button3', :update=>'display', :url=>{:action=>'update_debugger'}, :with => "button_id", :on => 'changed' %>
<%= end_form_tag %>
<%= render :partial =>'debug' %>
...

#----- controller.rb
...
def update_debugger
  render :partial => 'debug'
end
...

#----- _debug.rhtml
<span id="display"> params are: <%= params.inspect %> </span>


The idea is that every time a radio button is pressed on index.rhtml, the 'debug' partial is automatically updated, which will in turn update params.inspect, which includes the hash key "button_id" and the value of whichever button was pressed. 

The code above successfully updates the partial via ajax request.  However, I only got this to work for the first time a button is pressed, i.e., if I press button 1 it updates, if I then press button 2 it updates, but if I try pressing button 1, it doesn't update...I don't know why it's like that...