Radio buttons refusing to load checked

Hi,

Having big problems with radio buttons that just don’t make sense:

<%= radio_button “events”, “impact_type”, true %> Positive
<%= radio_button “events”, “impact_type”, false %> Negative

This should create two radio buttons with the first one checked by
default, right? Cos it doesn’t :frowning:

Any ideas would be great,
Thanks,
Bex

Becky F. wrote:

Hi,

Having big problems with radio buttons that just don’t make sense:

<%= radio_button “events”, “impact_type”, true %> Positive
<%= radio_button “events”, “impact_type”, false %> Negative

This should create two radio buttons with the first one checked by
default, right? Cos it doesn’t :frowning:

Any ideas would be great,
Thanks,
Bex

try 1 and 0 instead of true and false

calling the boolean field directly gives you a 1 or 0. You only get the
true/false if you call the method with a ?

So the form helper tries to match the values of the option buttons to
@events.impact_type, which gives a 1 or 0.

Hi Becky,

Try this instead:

<%= radio_button “events”, “impact_type”, true, :checked => true %>

The API for
radio_buttonhttp://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000395indicates
the 3rd param as the value
of the radio button, not whether the checked attribute it set or not.

But I guess you might have mistaken it with the API for
radio_button_taghttp://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000501
.


choonkeat

Becky F. wrote:

Hi,

Having big problems with radio buttons that just don’t make sense:

<%= radio_button “events”, “impact_type”, true %> Positive
<%= radio_button “events”, “impact_type”, false %> Negative

This should create two radio buttons with the first one checked by
default, right? Cos it doesn’t :frowning:

Any ideas would be great,
Thanks,
Bex

Hi,

Try using

<%= radio_button “events”, “impact_type”, “true”, {:checked =>
‘checked’} %>

hope this helps

-cd

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs