lib/merb-helpers/form/builder.rb in merb-helpers-1.0.12 vs lib/merb-helpers/form/builder.rb in merb-helpers-1.0.13
- old
+ new
@@ -129,11 +129,11 @@
# Unless the method is :get, fake out the method using :post
attrs[:method] = :post unless attrs[:method] == :get
# Use a fake PUT if the object is not new, otherwise use the method
# passed in. Defaults to :post if no method is set.
- method ||= (@obj.respond_to?(:new_record?) && !@obj.new_record?) || (@obj.respond_to?(:new?) && !@obj.new?) ? :put : :post
+ method ||= (@obj.respond_to?(:new?) && !@obj.new?) || (@obj.respond_to?(:new_record?) && !@obj.new_record?) ? :put : :post
attrs[:enctype] = "multipart/form-data" if attrs.delete(:multipart) || @multipart
method == :post || method == :get ? "" : fake_out_method(attrs, method)
end
@@ -162,11 +162,11 @@
end
def update_bound_select(method, attrs)
attrs[:value_method] ||= method
attrs[:text_method] ||= attrs[:value_method] || :to_s
- attrs[:selected] ||= control_value(attrs[:value_method])
+ attrs[:selected] ||= control_value(method)
end
def update_unbound_controls(attrs, type)
case type
when "checkbox"
@@ -372,11 +372,13 @@
attrs.merge!(:id => "#{@name}_#{method}") unless attrs[:id]
super
end
def update_unbound_controls(attrs, type)
- attrs.merge!(:id => attrs[:name]) if attrs[:name] && !attrs[:id]
-
+ if attrs[:name] && !attrs[:id]
+ # '[' and ']' are illegal in HTML id attributes
+ attrs.merge!(:id => attrs[:name].to_s.gsub(/(\[|\])/, '_'))
+ end
case type
when "text", "radio", "password", "hidden", "checkbox", "file"
add_css_class(attrs, type)
end
super