Permalink
Browse files

Support overriding the true/false label and values for select boolean…

… fields in the Sequel plugin
  • Loading branch information...
1 parent 9c56e6c commit 552f7c26af24d3863faa4b006e2e97b865124772 @jeremyevans committed Aug 25, 2011
Showing with 13 additions and 1 deletion.
  1. +4 −0 CHANGELOG
  2. +1 −1 lib/sequel/plugins/forme.rb
  3. +8 −0 spec/sequel_plugin_spec.rb
View
@@ -1,3 +1,7 @@
+=== HEAD
+
+* Support overriding the true/false label and values for select boolean fields in the Sequel plugin (jeremyevans)
+
=== 0.6.0 (2011-08-01)
* Fix wrapping for :as=>:radio boolean fields to handle them like association :as=>:radio fields (jeremyevans)
@@ -387,7 +387,7 @@ def input_boolean(sch)
v = opts[:value] || obj.send(field)
opts[:value] = (v ? 't' : 'f') unless v.nil?
opts[:add_blank] = true
- opts[:options] = [['True', 't'], ['False', 'f']]
+ opts[:options] = [[opts[:true_label]||'True', opts[:true_value]||'t'], [opts[:false_label]||'False', opts[:false_value]||'f']]
_input(:select, opts)
else
opts[:checked] = obj.send(field)
@@ -138,6 +138,14 @@ class AlbumInfo < Sequel::Model; end
@c.input(:gold).to_s.should == '<label>Gold: <select id="album_gold" name="album[gold]"><option value=""></option><option selected="selected" value="t">True</option><option value="f">False</option></select></label>'
end
+ specify "should respect :true_label and :false_label options for tri-valued boolean fields" do
+ @b.input(:gold, :true_label=>"Foo", :false_label=>"Bar").to_s.should == '<label>Gold: <select id="album_gold" name="album[gold]"><option value=""></option><option value="t">Foo</option><option selected="selected" value="f">Bar</option></select></label>'
+ end
+
+ specify "should respect :true_value and :false_value options for tri-valued boolean fields" do
+ @b.input(:gold, :true_value=>"Foo", :false_value=>"Bar").to_s.should == '<label>Gold: <select id="album_gold" name="album[gold]"><option value=""></option><option value="Foo">True</option><option value="Bar">False</option></select></label>'
+ end
+
specify "should use a checkbox for dual-valued boolean fields" do
@b.input(:platinum).to_s.should == '<label><input id="album_platinum_hidden" name="album[platinum]" type="hidden" value="f"/><input id="album_platinum" name="album[platinum]" type="checkbox" value="t"/> Platinum</label>'
@c.input(:platinum).to_s.should == '<label><input id="album_platinum_hidden" name="album[platinum]" type="hidden" value="f"/><input checked="checked" id="album_platinum" name="album[platinum]" type="checkbox" value="t"/> Platinum</label>'

0 comments on commit 552f7c2

Please sign in to comment.