Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
Backport pull request heartcombo#622 to simple_form 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
David Ruyer committed May 25, 2015
1 parent 95a8d87 commit 7d18fb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 8 additions & 2 deletions lib/simple_form/inputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ def initialize(builder, attribute_name, column, input_type, options = {})
@html_classes = SimpleForm.additional_classes_for(:input) { additional_classes }

@input_html_classes = @html_classes.dup
@input_html_options = html_options_for(:input, input_html_classes).tap do |o|
@input_html_options = {}
end

def input_html_options
html_options = html_options_for(:input, input_html_classes).tap do |o|
o[:readonly] = true if has_readonly?
o[:disabled] = true if has_disabled?
o[:autofocus] = true if has_autofocus?
end
@input_html_options.merge! html_options
end

def input
Expand Down Expand Up @@ -129,8 +134,9 @@ def reflection_or_attribute_name
def html_options_for(namespace, css_classes)
html_options = options[:"#{namespace}_html"]
html_options = html_options ? html_options.dup : {}
html_options.reverse_merge!(@builder.wrapper.options[:"#{namespace}_html"] || {})
css_classes << html_options[:class] if html_options.key?(:class)
html_options[:class] = css_classes unless css_classes.empty?
html_options[:class] = css_classes.uniq unless css_classes.empty?
html_options
end

Expand Down
18 changes: 11 additions & 7 deletions lib/simple_form/wrappers/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ def use(name, options=nil, &block)
return wrapper(name, options, &block)
end

if options && options.keys != [:wrap_with]
ActiveSupport::Deprecation.warn "Passing :tag, :class and others to use is deprecated. " \
"Please invoke b.use #{name.inspect}, :wrap_with => #{options.inspect} instead."
options = { :wrap_with => options }
end
# if options && options.keys != [:wrap_with]
# ActiveSupport::Deprecation.warn "Passing :tag, :class and others to use is deprecated. " \
# "Please invoke b.use #{name.inspect}, :wrap_with => #{options.inspect} instead."
# options = { :wrap_with => options }
# end

if options && wrapper = options[:wrap_with]
@components << Single.new(name, wrapper)
if options && options[:wrap_with]
@options[:"#{name}_html"] = options.except(:wrap_with)
@components << Single.new(name, options[:wrap_with])
elsif options
@options[:"#{name}_html"] = options
@components << name
else
@components << name
end
Expand Down

0 comments on commit 7d18fb1

Please sign in to comment.