Skip to content

Commit

Permalink
Use a more common name :checkboxes instead of :checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Mar 27, 2012
1 parent 46b71b4 commit 74a6997
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Expand Up @@ -72,7 +72,7 @@ Use ranges as options for your select tags

= f.input :year, :options => (1950..Time.now.year)

Options may also be rendered as **:radios** and **:checks**
Options may also be rendered as **:radios** and **:checkboxes**

= f.input :user, :options => User.all.map(&:name), :as => :radios

Expand Down Expand Up @@ -109,7 +109,7 @@ Mapping | Input | Column Type
**:date** |date field |date, datetime, timestamps
**:select** |select |-
**:radios** |radio buttons |-
**:checks** |check boxes |-
**:checkboxes** |check boxes |-


### Validations
Expand Down
8 changes: 4 additions & 4 deletions lib/padrino-fields/form_builder.rb
Expand Up @@ -46,7 +46,7 @@ def input(attribute, options={})
def default_input(attribute,type,options={})
input_options = options.keep_if {|key, value| key != :as}
if options[:options] || options[:grouped_options]
if type==:radios || type == :checks
if type==:radios || type == :checkboxes
collect_inputs_as(attribute,type,input_options)
else
select(attribute,input_options)
Expand Down Expand Up @@ -117,16 +117,16 @@ def collection_input(attribute,type,item, options={})
unchecked_value = options.delete(:uncheck_value) || '0'
options.reverse_merge!(:id => field_id(attribute), :value => '1')
options.reverse_merge!(:checked => true) if values_matches_field?(attribute, options[:value])
klass = css_class(attribute,type,options[:disabled])
name = type == :checks ? field_name(attribute) + '[]' : field_name(attribute)
klass = css_class(attribute, type.to_s.singularize, options[:disabled])
name = type == :checkboxes ? field_name(attribute) + '[]' : field_name(attribute)
if item.is_a?(Array)
text, value = item[0], item[1]
else
text = item; value = item;
end
id = field_id(attribute) + "_" + domize(text)
opts = html_options(attribute,type,options.merge(:id => id, :class => klass, :value => value))
if type == :checks
if type == :checkboxes
html = @template.hidden_field_tag(options[:name] || name, :value => unchecked_value, :id => nil)
input_item = @template.check_box_tag(name, opts)
else
Expand Down
12 changes: 6 additions & 6 deletions test/test_form_builder.rb
Expand Up @@ -116,20 +116,20 @@ def setup
end

should "return a collection of checkboxes" do
actual = field.input(:string, :options => ["Ann","Bob"], :as => :checks)
assert_has_tag("label", :class => "checks", :for => "person_string_ann", content:"Ann") { actual }
actual = field.input(:string, :options => ["Ann","Bob"], :as => :checkboxes)
assert_has_tag("label", :class => "checkboxes", :for => "person_string_ann", content:"Ann") { actual }
assert_has_tag("input", type:"checkbox", value:"Ann", id:"person_string_ann", name:"person[string][]") { actual }
assert_has_tag("label", :class => "checks", :for => "person_string_bob", content:"Bob") { actual }
assert_has_tag("label", :class => "checkboxes", :for => "person_string_bob", content:"Bob") { actual }
assert_has_tag("input", type:"checkbox", value:"Bob", id:"person_string_bob", name:"person[string][]") { actual }
assert_has_tag("input", type:"hidden", name:"person[string][]", value:"0") { actual }
end

should "return a collection of checkboxes using a multi-dimensional array" do
actual = field.input(:string, :options => [["Ann",1],["Bob",2]], :as => :checks)
assert_has_tag("label", :class => "checks", :for => "person_string_ann", content:"Ann") { actual }
actual = field.input(:string, :options => [["Ann",1],["Bob",2]], :as => :checkboxes)
assert_has_tag("label", :class => "checkboxes", :for => "person_string_ann", content:"Ann") { actual }
assert_has_tag("input", type:"checkbox", value:"1", id:"person_string_ann", name:"person[string][]") { actual }
assert_has_tag("input", type:"hidden", name:"person[string][]", value:"0") { actual }
assert_has_tag("label", :class => "checks", :for => "person_string_bob", content:"Bob") { actual }
assert_has_tag("label", :class => "checkboxes", :for => "person_string_bob", content:"Bob") { actual }
assert_has_tag("input", type:"checkbox", value:"2", id:"person_string_bob", name:"person[string][]") { actual }
assert_has_tag("input", type:"hidden", name:"person[string][]", value:"0") { actual }
end
Expand Down

0 comments on commit 74a6997

Please sign in to comment.