Class: Formtastic::Inputs::TimeInput

Inherits:
Object
  • Object
show all
Includes:
Base, Base::Timeish
Defined in:
lib/formtastic/inputs/time_input.rb

Overview

Outputs a series of select boxes for the fragments that make up a time (hour, minute, second). Unless :ignore_date is true, it will render hidden inputs for the year, month and day as well, defaulting to Time.current if the form object doesn't have a value, much like Rails' own time_select.

See Also:

  • Timeish module for documetation of date, time and datetime input options.

Instance Attribute Summary

Attributes included from Base

#builder, #method, #object, #object_name, #options, #template

Instance Method Summary collapse

Methods included from Base::Timeish

#date_fragments, #default_date_fragments, #fragment_id, #fragment_input_html, #fragment_label, #fragment_label_html, #fragment_name, #fragment_wrapping, #fragment_wrapping_html_options, #fragments_inner_wrapping, #fragments_label, #fragments_wrapping, #fragments_wrapping_html_options, #i18n_date_fragments, #include_blank?, #position, #positions, #time_fragments, #to_html, #value

Methods included from Base

#initialize, #warn_and_correct_option!

Methods included from Base::Wrapping

#input_wrapping, #wrapper_dom_id, #wrapper_html_options

Methods included from Base::Labelling

#label_from_options, #label_html, #label_html_options, #label_text, #localized_label, #render_label?, #requirement_text, #requirement_text_or_proc

Methods included from Base::Associations

#association, #association_primary_key, #belongs_to?, #has_many?, #reflection

Methods included from Base::Fileish

#file?

Methods included from Base::Validations

#autofocus?, #column_limit, #limit, #not_required_through_negated_validation!, #not_required_through_negated_validation?, #optional?, #required?, #required_attribute?, #responds_to_global_required?, #validation_integer_only?, #validation_limit, #validation_max, #validation_min, #validation_step, #validations, #validations?, #validator_relevant?

Methods included from Base::Naming

#as, #attributized_method_name, #humanized_method_name, #input_name, #sanitized_method_name, #sanitized_object_name

Methods included from Base::Hints

#hint?, #hint_html, #hint_text, #hint_text_from_options

Methods included from Base::Errors

#error_first_html, #error_html, #error_keys, #error_list_html, #error_none_html, #error_sentence_html, #errors, #errors?

Methods included from Base::Database

#column, #column?

Methods included from Base::Options

#formtastic_options, #input_options

Methods included from Base::Html

#dom_id, #dom_index, #input_html_options, #to_html

Instance Method Details

#fragment_value(fragment) ⇒ Object



22
23
24
# File 'lib/formtastic/inputs/time_input.rb', line 22

def fragment_value(fragment)
  value_or_default_value.send(fragment)
end

#fragmentsObject

we don't want year / month / day fragments if :ignore_date => true



14
15
16
# File 'lib/formtastic/inputs/time_input.rb', line 14

def fragments
  time_fragments
end

#hidden_fragmentsObject



26
27
28
29
30
31
32
33
34
# File 'lib/formtastic/inputs/time_input.rb', line 26

def hidden_fragments
  if !options[:ignore_date]
    date_fragments.map do |fragment|
      template.hidden_field_tag("#{object_name}[#{fragment_name(fragment)}]", fragment_value(fragment), :id => fragment_id(fragment), :disabled => input_html_options[:disabled] )
    end.join.html_safe
  else
    super
  end
end

#value_or_default_valueObject



18
19
20
# File 'lib/formtastic/inputs/time_input.rb', line 18

def value_or_default_value
  value ? value : Time.current
end