Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow overriding the type of input for schema columns and association…

…s in the Sequel plugin
  • Loading branch information...
commit 3ddcf37c3970542fb96a5a940269b8ded1e3ce2f 1 parent 9a5d0ab
@jeremyevans authored
View
2  CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Allow overriding the type of input for schema columns and associations in the Sequel plugin (jeremyevans)
+
* Add the label before the error option, so the error always comes after the label (jeremyevans)
* Always add error class to formatted input tag, regardless of error_handler (jeremyevans)
View
6 lib/sequel/plugins/forme.rb
@@ -154,7 +154,8 @@ def input
handle_errors(field)
handle_validations(field)
- if sch = obj.db_schema[field]
+ type = opts[:type]
+ if !type && (sch = obj.db_schema[field])
meth = :"input_#{sch[:type]}"
opts[:id] = form.namespaced_id(field) unless opts.has_key?(:id)
opts[:name] = form.namespaced_name(field) unless opts.has_key?(:name)
@@ -169,7 +170,7 @@ def input
else
input_other(sch)
end
- elsif ref = obj.model.association_reflection(field)
+ elsif !type && (ref = obj.model.association_reflection(field))
::Forme.attr_classes(opts[:wrapper_attr], ref[:type])
meth = :"association_#{ref[:type]}"
if respond_to?(meth, true)
@@ -179,7 +180,6 @@ def input
end
else
rt = obj.respond_to?(field)
- type = opts[:type]
raise(Error, "Unrecognized field used: #{field}") unless rt || type
meth = :"input_#{type}"
opts[:value] = nil unless rt || opts.has_key?(:value)
View
4 spec/sequel_plugin_spec.rb
@@ -158,6 +158,10 @@ class AlbumInfo < Sequel::Model; end
@c.input(:artist).to_s.should == '<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>'
end
+ specify "should allow overriding default input type using a :type option" do
+ @b.input(:artist, :type=>:string, :value=>nil).to_s.should == '<label>Artist: <input id="album_artist" name="album[artist]" type="text"/></label>'
+ end
+
specify "should use a required wrapper tag for many_to_one required associations" do
@b.input(:artist, :required=>true, :wrapper=>:li).to_s.should == '<li class="many_to_one required"><label>Artist<abbr title="required">*</abbr>: <select id="album_artist_id" name="album[artist_id]" required="required"><option value=""></option><option selected="selected" value="1">a</option><option value="2">d</option></select></label></li>'
end
Please sign in to comment.
Something went wrong with that request. Please try again.