Skip to content

Instantly share code, notes, and snippets.

@adelcambre
Created October 29, 2008 00:57
Show Gist options
  • Select an option

  • Save adelcambre/20570 to your computer and use it in GitHub Desktop.

Select an option

Save adelcambre/20570 to your computer and use it in GitHub Desktop.
commit ed47134b48efffcf717fb5afbcb918e51a305e54
Author: Matt Aimonetti <[email protected]>
Date: Thu Oct 16 19:09:47 2008 -0700
Fix: merb-helpers - Radio groups should only have one element with the checked property - Ticket #271
aczid fixed the problem by only setting the radio button as true if it has a value
diff --git a/merb-helpers/lib/merb-helpers/form/builder.rb b/merb-helpers/lib/merb-helpers/form/builder.rb
index 53b7ca9..96a463e 100644
--- a/merb-helpers/lib/merb-helpers/form/builder.rb
+++ b/merb-helpers/lib/merb-helpers/form/builder.rb
@@ -72,7 +72,7 @@ module Merb::Helpers::Form::Builder
val = control_value(method)
arr.map do |attrs|
attrs = {:value => attrs} unless attrs.is_a?(Hash)
- attrs[:checked] ||= (val == attrs[:value])
+ attrs[:checked] = true if (val == attrs[:value])
radio_group_item(method, attrs)
end.join
end
diff --git a/merb-helpers/spec/merb_helpers_form_spec.rb b/merb-helpers/spec/merb_helpers_form_spec.rb
index c0c5363..47bbdaa 100644
--- a/merb-helpers/spec/merb_helpers_form_spec.rb
+++ b/merb-helpers/spec/merb_helpers_form_spec.rb
@@ -791,6 +791,13 @@ describe "bound_radio_group" do
radio[0].should match_tag(:input, :id => 'bar_id')
radio[1].should match_tag(:label, :for => 'bar_id')
end
+
+ it "should only have one element with the checked property" do
+ r = @c.render :basic
+ radio = r.scan(/<[^>]*>/)[2..-2]
+ radio[0].should match_tag(:input, :checked => "checked")
+ radio[3].should_not match_tag(:input, :checked => "false")
+ end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment