Skip to content

Commit

Permalink
Support for btn input addons
Browse files Browse the repository at this point in the history
  • Loading branch information
buren committed Sep 14, 2014
1 parent d40656c commit 1094c07
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/bh/helpers/form/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def field_in_group(field, prefix, suffix)
end

def input_addon(addon)
content_tag :span, addon, class: 'input-group-addon' if addon
if addon && addon.include?('class="btn')
content_tag :span, addon, class: 'input-group-btn'
elsif addon
content_tag :span, addon, class: 'input-group-addon'
end
end

def input_group_container(has_addons, &block)
Expand Down
5 changes: 5 additions & 0 deletions spec/helpers/form/field_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def self.field_helpers_to_test
it { expect(form).to match %r{<div class="input-group"><.+?><span class="input-group-addon">Jr</span></div>}m }
end

context 'given a suffix option that is a button, prints the correct addon wrapper class' do
let(:options) { {suffix: content_tag(:button, 'hey', class: 'btn btn-default')} }
it { expect(form).to match %r{<div class="input-group"><.+?><span class="input-group-btn"><button class="btn btn-default">hey</button></span></div>}m }
end

specify 'not given an error, does not apply has-error to the form group' do
expect(form).not_to include 'has-error'
end
Expand Down

0 comments on commit 1094c07

Please sign in to comment.