Edit is not working properly for radio_button


#1

Hi,

I m trying to edit contact info… all other data other than radio button
are getting reflected in edit page … But the same works fine while
creating new contact i.e it allows only one email id to be set as
primary but the same not working in edit… it allows user 2 select both
radio buttons
the view code is as follows
.
.
.

<% i= 0 %> <% for email in @contact.emails %> <% fields_for "contact[email_attributes][]", email do |e| %> <% end %> <% end %>
Email Addresses
Email <%= i=i+1 %> <%= e.select ('email_type',%w{Business Personal}, :include_blank => false) %> <%= e.text_field :email,:size=>"35",:maxlength=>"80" %> <%= e.radio_button('isprimary', "1") %>
. . .

#2

Hello,

I also have the same problem setting business categories as primary in
my edit_categories page using a radio_button. The radio_button’s
behavior changes, all buttons can be selected and can’t be de-selected.
Everything works fine on my “new” page. My codes is also like what Raji
had. I added an onclick action just so user can de-select the
radio_button(it’s now like a checkbox) and a note that user can just set
one category as primary.

Does anyone know a better way to solve this problem in a much cleaner
way? Please help.

I had this helper method which checks if the data already exist:

def fields_for_business_category(category, &block)
prefix = category.new_record? ? ‘’ : ‘existing_’
fields_for("#{prefix}category_attributes[]", category, &block)
end

This is my view:

<% category = business_category %>
<% fields_for_business_category(category) do |category_form| %>
<%= category_select_tag(“category_id”, category_form, {:class =>
‘search’})%>
<%= category_form.radio_button(“primary_category”, “Y”,
:onmousedown=>“this.chk = this.checked”, :onclick=>“if (this.chk)
this.checked = false”)%>
<%end%>

Thanks in advance…:slight_smile: