lib/formtastic/inputs/base/timeish.rb in formtastic-2.0.2 vs lib/formtastic/inputs/base/timeish.rb in formtastic-2.1.0.beta1

- old
+ new

@@ -76,13 +76,13 @@ # <%= f.input :publish_at, :as => :date, :order => [:month, :day, :year] %> # # @example Include seconds with times (excluded by default) # <%= f.input :publish_at, :as => :time, :include_seconds => true %> # - # @example Specify if there should be a blank option at the start of each select or not - # <%= f.input :publish_at, :as => :time, :include_blank=> true %> - # <%= f.input :publish_at, :as => :time, :include_blank=> false %> + # @example Specify if there should be a blank option at the start of each select or not. Note that, unlike select inputs, :include_blank does not accept a string value. + # <%= f.input :publish_at, :as => :time, :include_blank => true %> + # <%= f.input :publish_at, :as => :time, :include_blank => false %> # # @todo Document i18n # @todo Check what other Rails options are supported (`start_year`, `end_year`, `use_month_numbers`, `use_short_month`, `add_month_numbers`, `prompt`), write tests for them, and otherwise support them # @todo Could we take the rendering from Rails' helpers and inject better HTML in and around it rather than re-inventing the whee? module Timeish @@ -154,14 +154,22 @@ def value object.send(method) if object && object.respond_to?(method) end def fragment_input_html(fragment) - opts = input_options.merge(:prefix => object_name, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?) + opts = input_options.merge(:prefix => fragment_prefix, :field_name => fragment_name(fragment), :default => value, :include_blank => include_blank?) template.send(:"select_#{fragment}", value, opts, input_html_options.merge(:id => fragment_id(fragment))) end + def fragment_prefix + if builder.options.key?(:index) + object_name + "[#{builder.options[:index]}]" + else + object_name + end + end + # TODO extract to BlankOptions or similar -- Select uses similar code def include_blank? options.key?(:include_blank) ? options[:include_blank] : builder.include_blank_for_select_by_default end @@ -191,11 +199,11 @@ end def fragments_label if render_label? template.content_tag(:legend, - builder.label(method, label_text, :for => "#{input_html_options[:id]}_1i"), + builder.label(method, label_text, :for => fragment_id(fragments.first)), :class => "label" ) else "".html_safe end @@ -207,9 +215,17 @@ ) end def hidden_fragments "".html_safe + end + + def hidden_field_name(fragment) + if builder.options.key?(:index) + "#{object_name}[#{builder.options[:index]}][#{fragment_name(fragment)}]" + else + "#{object_name}[#{fragment_name(fragment)}]" + end end end end end \ No newline at end of file