Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use a more common name :checkboxes instead of :checks.

  • Loading branch information...
commit 74a6997f6aade0add3e19f070cddd2fc05858622 1 parent 46b71b4
@whitequark whitequark authored
View
4 README.markdown
@@ -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
@@ -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
View
8 lib/padrino-fields/form_builder.rb
@@ -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)
@@ -117,8 +117,8 @@ 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
@@ -126,7 +126,7 @@ def collection_input(attribute,type,item, options={})
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
View
12 test/test_form_builder.rb
@@ -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

0 comments on commit 74a6997

Please sign in to comment.
Something went wrong with that request. Please try again.