Skip to content

Commit

Permalink
Add CheckBoxInput along with some Choices refactorings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Bellantoni committed Nov 4, 2011
1 parent df4c870 commit 79baa77
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 11 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -38,7 +38,6 @@ Tried to mimic its code structure as much as possible.
## To Do
* Field Types
* Basic Formtastic
* :check_boxes
* :time_zone
* :date
* :datetime
Expand Down
1 change: 1 addition & 0 deletions lib/formtastic-bootstrap/inputs.rb
@@ -1,5 +1,6 @@
require "formtastic-bootstrap/inputs/base"
require "formtastic-bootstrap/inputs/boolean_input"
require "formtastic-bootstrap/inputs/check_boxes_input"
require "formtastic-bootstrap/inputs/email_input"
require "formtastic-bootstrap/inputs/hidden_input"
require "formtastic-bootstrap/inputs/number_input"
Expand Down
10 changes: 1 addition & 9 deletions lib/formtastic-bootstrap/inputs/base/choices.rb
Expand Up @@ -14,7 +14,7 @@ def choices_wrapping(&block)
end

def choices_wrapping_html_options
# Call the Formtastic one explicity and append?
# TODO Call the Formtastic one explicity and append?
{ :class => "choices input" }
end

Expand All @@ -29,14 +29,6 @@ def choices_group_wrapping_html_options
{ :class => "choices-group inputs-list" }
end

def choice_html(choice)
template.content_tag(:label, label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)) do
builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<

choice_label(choice)
end
end

def choice_label(choice)
"\n".html_safe + template.content_tag(:span) do
# (choice.is_a?(Array) ? choice.first : choice).to_s
Expand Down
1 change: 1 addition & 0 deletions lib/formtastic-bootstrap/inputs/boolean_input.rb
@@ -1,3 +1,4 @@
# TODO See if this can be refactored to make use of some of the Choices code.
module FormtasticBootstrap
module Inputs
class BooleanInput < Formtastic::Inputs::BooleanInput
Expand Down
35 changes: 35 additions & 0 deletions lib/formtastic-bootstrap/inputs/check_boxes_input.rb
@@ -0,0 +1,35 @@
module FormtasticBootstrap
module Inputs
class CheckBoxesInput < Formtastic::Inputs::CheckBoxesInput
include Base
include Base::Choices

def to_html
input_wrapping do
legend_html <<
hidden_field_for_all <<
choices_wrapping do
choices_group_wrapping do
collection.map { |choice|
choice_wrapping(choice_wrapping_html_options(choice)) do
choice_html(choice)
end
}.join("\n").html_safe
end
end
end
end

def choice_html(choice)
template.content_tag(:label,
hidden_fields? ?
check_box_with_hidden_input(choice) :
check_box_without_hidden_input(choice) <<
choice_label(choice),
label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
)
end

end
end
end
8 changes: 8 additions & 0 deletions lib/formtastic-bootstrap/inputs/radio_input.rb
Expand Up @@ -19,6 +19,14 @@ def to_html
end
end

def choice_html(choice)
template.content_tag(:label, label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)) do
builder.radio_button(input_name, choice_value(choice), input_html_options.merge(choice_html_options(choice)).merge(:required => false)) <<

choice_label(choice)
end
end

end
end
end

0 comments on commit 79baa77

Please sign in to comment.