Skip to content
Browse files

Merge pull request #52 from sodabrew/appended_and_prepended_text

adding in appended text
  • Loading branch information...
2 parents 3800c7f + 76aaf20 commit 4c3e70f8c0cf08853697aba3792c643923a2e381 @sodabrew sodabrew committed Feb 7, 2013
Showing with 38 additions and 4 deletions.
  1. +9 −0 README.md
  2. +29 −4 lib/formtastic-bootstrap/inputs/base/wrapping.rb
View
9 README.md
@@ -147,6 +147,15 @@ To create a Prepended Text field, use the ```:prepend``` option. This works on
<% end %>
<% end %>
+#### Appended Text
+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```
+
+ <%= semantic_form_for @user do |f| %>
+ <%= f.inputs do %>
+ <%= f.input :handle, :append => '%' %>
+ <% end %>
+ <% end %>
+
## Contributing
### Contributors
View
33 lib/formtastic-bootstrap/inputs/base/wrapping.rb
@@ -9,9 +9,19 @@ def bootstrap_wrapping(&block)
control_group_wrapping do
control_label_html <<
controls_wrapping do
- if options[:prepend]
- prepended_input_wrapping do
- [template.content_tag(:span, options[:prepend], :class => 'add-on'), yield, hint_html].join("\n").html_safe
+ if options[:prepend] || options[:append]
+ if options[:prepend] && options[:append]
+ prepended_and_appended_input_wrapping do
+ [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
+ end
+ elsif options[:prepend]
+ prepended_input_wrapping do
+ [template.content_tag(:span, options[:prepend], :class => 'add-on'), yield, hint_html].join("\n").html_safe
+ end
+ elsif options[:append]
+ appended_input_wrapping do
+ [yield, template.content_tag(:span, options[:append], :class => 'add-on'), hint_html].join("\n").html_safe
+ end
end
else
[yield, hint_html].join("\n").html_safe
@@ -52,7 +62,22 @@ def prepended_input_wrapping(&block)
yield
end
end
+
+ # Bootstrap append feature
+ def appended_input_wrapping(&block)
+ template.content_tag(:div, :class => 'input-append') do
+ yield
+ end
+ end
+
+ # Bootstrap prepend and append feature
+ def prepended_and_appended_input_wrapping(&block)
+ template.content_tag(:div, :class => 'input-prepend input-append') do
+ yield
+ end
+ end
+
end
end
end
-end
+end

0 comments on commit 4c3e70f

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