Skip to content

Commit

Permalink
Wrap the date helpers inside a div with the multiple selects fix class
Browse files Browse the repository at this point in the history
  • Loading branch information
carloslopes committed Jan 1, 2014
1 parent e07cd94 commit 9c32959
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
26 changes: 23 additions & 3 deletions lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class FormBuilder < ActionView::Helpers::FormBuilder

FORM_HELPERS = %w{text_field password_field text_area file_field
number_field email_field telephone_field phone_field url_field
select collection_select date_select time_select datetime_select}
select collection_select}

DATE_HELPERS = %w{date_select time_select datetime_select}

delegate :content_tag, to: :@template
delegate :capture, to: :@template
Expand Down Expand Up @@ -34,6 +36,22 @@ def initialize(object_name, object, template, options, proc=nil)
end
end

DATE_HELPERS.each do |method_name|
define_method(method_name) do |name, options = {}, html_options = {}|
options.symbolize_keys!
html_options.symbolize_keys!

label = options.delete(:label)
label_class = hide_class if options.delete(:hide_label)
help = options.delete(:help)

form_group(name, label: { text: label, class: label_class }, help: help) do
html_options[:class] = "form-control #{html_options[:class]}".rstrip
content_tag(:div, super(name, options, html_options), class: multiple_selects_class)
end
end
end

def check_box(name, options = {}, checked_value = '1', unchecked_value = '0')
options = options.symbolize_keys!

Expand Down Expand Up @@ -123,8 +141,6 @@ def normalize_args!(method_name, args)
args << {} while args.length < 3
elsif method_name == "collection_select"
args << {} while args.length < 5
elsif method_name =~ /_select/
args << {} while args.length < 2
end
end

Expand All @@ -148,6 +164,10 @@ def static_class
"form-control-static"
end

def multiple_selects_class
'rails-bootstrap-forms-multiple-selects'
end

def has_error?(name)
object.respond_to?(:errors) && !(name.nil? || object.errors[name].empty?)
end
Expand Down
Loading

0 comments on commit 9c32959

Please sign in to comment.