Skip to content

Commit

Permalink
Add support for simultaneous prepend and append of add_on spans.
Browse files Browse the repository at this point in the history
  • Loading branch information
sapientpants committed Mar 22, 2012
1 parent c8b8701 commit d321bad
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/twitter_bootstrap_form_for/form_builder.rb
Expand Up @@ -38,8 +38,10 @@ def inputs(legend = nil, options = {}, &block)
# and the appropriate markup. All toggle buttons should be rendered # and the appropriate markup. All toggle buttons should be rendered
# inside of here, and will not look correct unless they are. # inside of here, and will not look correct unless they are.
# #
def toggles(label = nil, &block) def toggles(label = nil, attribute = nil, &block)
template.content_tag(:div, :class => 'clearfix control-group') do classes = ['clearfix', 'control-group']
classes << 'error' if attribute && errors_on?(attribute)
template.content_tag(:div, :class => classes.join(' ')) do
template.concat template.content_tag(:label, label, :class => 'control-label') template.concat template.content_tag(:label, label, :class => 'control-label')
template.concat template.content_tag(:div, :class => "input controls") { block.call } template.concat template.content_tag(:div, :class => "input controls") { block.call }
end end
Expand Down Expand Up @@ -78,13 +80,24 @@ def inline(label = nil, &block)
options = args.extract_options! options = args.extract_options!
label = args.first.nil? ? '' : args.shift label = args.first.nil? ? '' : args.shift
classes = [ 'input', 'controls' ] classes = [ 'input', 'controls' ]
classes << ('input-' + options.delete(:add_on).to_s) if options[:add_on]
if options[:append]
classes << 'input-append'
append_add_on = options.delete(:append)
end

if options[:prepend]
classes << 'input-prepend'
prepend_add_on = options.delete(:prepend)
end


self.div_wrapper(attribute) do self.div_wrapper(attribute) do
template.concat self.label(attribute, label, :class => 'control-label') if label template.concat self.label(attribute, label, :class => 'control-label') if label
template.concat template.content_tag(:div, :class => classes.join(' ')) { template.concat template.content_tag(:div, :class => classes.join(' ')) {
template.concat template.content_tag(:span, prepend_add_on, :class => "add-on") if prepend_add_on
template.concat super(attribute, *(args << options)) template.concat super(attribute, *(args << options))
template.concat error_span(attribute) template.concat error_span(attribute)
template.concat template.content_tag(:span, append_add_on, :class => "add-on") if append_add_on
block.call if block.present? block.call if block.present?
} }
end end
Expand All @@ -99,7 +112,7 @@ def inline(label = nil, &block)
when :check_box when :check_box
{ :for => target, :class => :checkbox } { :for => target, :class => :checkbox }
when :radio_button when :radio_button
{ :class => :radio} { :class => :radio }
else else
{} {}
end end
Expand Down

0 comments on commit d321bad

Please sign in to comment.