Skip to content

Commit

Permalink
Respect :formatter option for radioset and checkboxset inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyevans committed Jan 28, 2016
1 parent ce0ee0d commit ccdb5eb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== HEAD

* Respect :formatter option for radioset and checkboxset inputs (jeremyevans)

* Add support for running with --enable-frozen-string-literal on ruby 2.3 (jeremyevans)

* Handle an explicit :value option for *_to_many association inputs in the Sequel plugin (jeremyevans)
Expand Down
1 change: 1 addition & 0 deletions lib/forme/transformers/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def _format_set(type, tag_attrs={})
r_opts = attrs.merge(tag_attrs).merge(:label=>label||value, :label_attr=>{:class=>:option}, :wrapper=>tag_wrapper)
r_opts[:value] ||= value if value
r_opts[:checked] ||= :checked if sel
r_opts[:formatter] = @opts[:formatter] if @opts[:formatter]

if name
r_opts[:name] ||= name
Expand Down
4 changes: 4 additions & 0 deletions spec/sequel_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def @ab.db_schema
@b.input(:platinum, :as=>:radio, :true_value=>"Foo", :false_value=>"Bar").to_s.must_equal '<span class="label">Platinum</span><label class="option"><input id="album_platinum_yes" name="album[platinum]" type="radio" value="Foo"/> Yes</label><label class="option"><input checked="checked" id="album_platinum_no" name="album[platinum]" type="radio" value="Bar"/> No</label>'
end

it "should respect :formatter=>:readonly option for boolean fields if :as=>:radio is used" do
@b.input(:platinum, :as=>:radio, :formatter=>:readonly).to_s.must_equal '<span class="label">Platinum</span><label class="option"><input disabled="disabled" id="album_platinum_yes" name="album[platinum]" type="radio" value="t"/> Yes</label><label class="option"><input checked="checked" disabled="disabled" id="album_platinum_no" name="album[platinum]" type="radio" value="f"/> No</label>'
end

it "should use a select box for many_to_one associations" do
@b.input(:artist).to_s.must_equal '<label>Artist: <select id="album_artist_id" name="album[artist_id]"><option value=""></option><option selected="selected" value="1">a</option><option value="2">d</option></select></label>'
@c.input(:artist).to_s.must_equal '<label>Artist: <select id="album_artist_id" name="album[artist_id]"><option value=""></option><option value="1">a</option><option selected="selected" value="2">d</option></select></label>'
Expand Down

0 comments on commit ccdb5eb

Please sign in to comment.