Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

… fields in the Sequel plugin
  • Loading branch information...
commit 552f7c26af24d3863faa4b006e2e97b865124772 1 parent 9c56e6c
@jeremyevans authored
View
4 CHANGELOG
@@ -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)
View
2  lib/sequel/plugins/forme.rb
@@ -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)
View
8 spec/sequel_plugin_spec.rb
@@ -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>'
Please sign in to comment.
Something went wrong with that request. Please try again.