Skip to content

Loading…

make the input method can accept a block #887

Closed
wants to merge 1 commit into from

2 participants

@zuozuo

Sometimes I need to add something other into the input wrapper <li>, so it can be convenient if the input can be called with a block, and the block code is inserted after the input in the page .

@justinfrench

Hi, thanks for the patch, but I'm nervous about accepting this right now without full consideration — it would effectively shut the door on what else we can use the block for.

My current approach is to define a custom input and incorporate the extra content there instead. Closing for now, sorry I don't have more time to go deep on this right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 21, 2012
  1. @zuozuo

    make input to accept a block

    zuozuo committed
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +4 −0 lib/formtastic/helpers/input_helper.rb
  3. +1 −1 lib/formtastic/inputs/base/wrapping.rb
View
1 .gitignore
@@ -15,3 +15,4 @@ Gemfile.lock
doc/
tmp
gemfiles/*.lock
+tags
View
4 lib/formtastic/helpers/input_helper.rb
@@ -236,6 +236,10 @@ def input(method, options = {})
options = options.dup # Allow options to be shared without being tainted by Formtastic
options[:as] ||= default_input_type(method, options)
+ if block_given?
+ options[:block_content] = template.capture(&block)
+ end
+
klass = input_class(options[:as])
klass.new(self, template, @object, @object_name, method, options).to_html
View
2 lib/formtastic/inputs/base/wrapping.rb
@@ -8,7 +8,7 @@ module Wrapping
# errors before the body of the input).
def input_wrapping(&block)
template.content_tag(:li,
- [template.capture(&block), error_html, hint_html].join("\n").html_safe,
+ [template.capture(&block), options[:block_content], error_html, hint_html].join("\n").html_safe,
wrapper_html_options
)
end
Something went wrong with that request. Please try again.