Permalink
Browse files

Now generating sanitized html ids for date and datetime selects.

Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information...
1 parent d89dc8d commit 7087fc807874a36f4807c1b228d257018e76c685 @josevalim josevalim committed with justinfrench Mar 6, 2009
Showing with 20 additions and 3 deletions.
  1. +5 −3 lib/formtastic.rb
  2. +15 −0 spec/formtastic_spec.rb
View
8 lib/formtastic.rb
@@ -577,14 +577,16 @@ def date_or_datetime_input(method, options)
list_items_capture = ""
(inputs + time_inputs).each do |input|
+ html_id = generate_html_id(method, "#{position[input]}i")
+
if options["discard_#{input}".intern]
break if time_inputs.include?(input)
- list_items_capture << template.hidden_field_tag("#{@object_name}[#{method}(#{position[input]}i)]", @object.send(method), :id => "#{@object_name}_#{method}_#{position[input]}i")
+ list_items_capture << template.hidden_field_tag("#{@object_name}[#{method}(#{position[input]}i)]", @object.send(method), :id => html_id)
else
- opts = set_options(options).merge({:prefix => @object_name, :field_name => "#{method}(#{position[input]}i)", :include_blank => options[:include_blank]})
+ opts = set_options(options).merge(:prefix => @object_name, :field_name => "#{method}(#{position[input]}i)")
item_label_text = I18n.t(input.to_s, :default => input.to_s, :scope => [:formtastic]).send(@@label_str_method)
list_items_capture << template.content_tag(:li,
- template.content_tag(:label, item_label_text, :for => "#{@object_name}_#{method}_#{position[input]}i") +
+ template.content_tag(:label, item_label_text, :for => html_id) +
template.send("select_#{input}".intern, @object.send(method), opts)
)
end
View
15 spec/formtastic_spec.rb
@@ -1640,6 +1640,21 @@ def custom(arg1, arg2, options = {})
output_buffer.should have_tag('form li.datetime fieldset ol li select', :count => 5)
end
+ it 'should generate a sanitized label for attribute' do
+ @bob.stub!(:publish_at)
+ @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :datetime))
+
+ semantic_form_for(@new_post) do |builder|
+ builder.semantic_fields_for(@bob) do |bob_builder|
+ concat(bob_builder.input(:publish_at, :as => :datetime))
+ end
+ end
+
+ 1.upto(5) do |i|
+ output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_publish_at_#{i}i']")
+ end
+ end
+
describe 'when :include_blank => true is set' do
before do
semantic_form_for(@new_post) do |builder|

0 comments on commit 7087fc8

Please sign in to comment.