Skip to content
Browse files

clean up and simplify input_html_options[:id], required small changes…

… to the id on hidden inputs
  • Loading branch information...
1 parent 46b1361 commit b46028c51febd5a811bc3805d8caa490223b8fc2 @justinfrench committed
View
8 lib/formtastic/inputs/hidden_input.rb
@@ -31,10 +31,12 @@ module Inputs
class HiddenInput
include NewBase
+ # Override to include :value set directly from options hash. The :value set in :input_html
+ # hash will be preferred over :value set directly in the options.
+ #
+ # @todo this is inconsistent with all other inputs, deprecate and remove
def input_html_options
- super[:id] = super[:id].gsub(/_id$/, '') # TODO: special case because we seem to test hidden input differently
- return {:value => options[:value]}.merge(super) if options.key?(:value)
- super
+ {:value => options[:value]}.merge(super)
end
def to_html
View
9 lib/formtastic/inputs/new_base/html.rb
@@ -11,14 +11,7 @@ def to_html
end
def input_html_options
- opts = options[:input_html] || {}
- opts[:id] ||= input_dom_id
-
- opts
- end
-
- def input_dom_id
- options[:input_html].try(:[], :id) || dom_id
+ { :id => dom_id }.merge(options[:input_html] || {})
end
def dom_id
View
2 lib/formtastic/inputs/new_base/labelling.rb
@@ -12,7 +12,7 @@ def label_html
def label_html_options
# opts = options_for_label(options) # TODO
opts = {}
- opts[:for] ||= input_dom_id
+ opts[:for] ||= input_html_options[:id]
opts
end
View
5 lib/formtastic/inputs/select_input.rb
@@ -172,11 +172,6 @@ def label_html_options
super.merge(:for => input_html_options[:id])
end
- def input_dom_id
- return "#{object_name}_#{association_primary_key}" if belongs_to?
- super
- end
-
def input_options
{:include_blank => include_blank?}.merge(super)
end
View
4 spec/inputs/hidden_input_spec.rb
@@ -42,7 +42,7 @@
end
it "should prefer :input_html over directly supplied options" do
- output_buffer.should have_tag("form li input#post_author[@type=\"hidden\"][@value=\"formtastic_value\"]")
+ output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"formtastic_value\"]")
end
it "should not render inline errors" do
@@ -82,7 +82,7 @@
end)
end
- attributes_to_check = [:secret, :author_id, :published, :reviewer, :author]
+ attributes_to_check = [:secret, :author_id, :published, :reviewer]
attributes_to_check.each do |a|
it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
end

0 comments on commit b46028c

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