Skip to content
This repository
Browse code

Merge pull request #52 from sodabrew/appended_and_prepended_text

adding in appended text
  • Loading branch information...
commit 4c3e70f8c0cf08853697aba3792c643923a2e381 2 parents 3800c7f + 76aaf20
Aaron Stone sodabrew authored
9 README.md
Source Rendered
@@ -147,6 +147,15 @@ To create a Prepended Text field, use the ```:prepend``` option. This works on
147 147 <% end %>
148 148 <% end %>
149 149
  150 +#### Appended Text
  151 +To create an Appended Text field, use the ```:append``` option. This works on any text field input type, like ```:url```, ```:search```, and of course ```:string```
  152 +
  153 + <%= semantic_form_for @user do |f| %>
  154 + <%= f.inputs do %>
  155 + <%= f.input :handle, :append => '%' %>
  156 + <% end %>
  157 + <% end %>
  158 +
150 159 ## Contributing
151 160
152 161 ### Contributors
33 lib/formtastic-bootstrap/inputs/base/wrapping.rb
@@ -9,9 +9,19 @@ def bootstrap_wrapping(&block)
9 9 control_group_wrapping do
10 10 control_label_html <<
11 11 controls_wrapping do
12   - if options[:prepend]
13   - prepended_input_wrapping do
14   - [template.content_tag(:span, options[:prepend], :class => 'add-on'), yield, hint_html].join("\n").html_safe
  12 + if options[:prepend] || options[:append]
  13 + if options[:prepend] && options[:append]
  14 + prepended_and_appended_input_wrapping do
  15 + [template.content_tag(:span, options[:prepend], :class => 'add-on'), yield, template.content_tag(:span, options[:append], :class => 'add-on'), hint_html].join("\n").html_safe
  16 + end
  17 + elsif options[:prepend]
  18 + prepended_input_wrapping do
  19 + [template.content_tag(:span, options[:prepend], :class => 'add-on'), yield, hint_html].join("\n").html_safe
  20 + end
  21 + elsif options[:append]
  22 + appended_input_wrapping do
  23 + [yield, template.content_tag(:span, options[:append], :class => 'add-on'), hint_html].join("\n").html_safe
  24 + end
15 25 end
16 26 else
17 27 [yield, hint_html].join("\n").html_safe
@@ -52,7 +62,22 @@ def prepended_input_wrapping(&block)
52 62 yield
53 63 end
54 64 end
  65 +
  66 + # Bootstrap append feature
  67 + def appended_input_wrapping(&block)
  68 + template.content_tag(:div, :class => 'input-append') do
  69 + yield
  70 + end
  71 + end
  72 +
  73 + # Bootstrap prepend and append feature
  74 + def prepended_and_appended_input_wrapping(&block)
  75 + template.content_tag(:div, :class => 'input-prepend input-append') do
  76 + yield
  77 + end
  78 + end
  79 +
55 80 end
56 81 end
57 82 end
58   -end
  83 +end

0 comments on commit 4c3e70f

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