Class: TemplateForm::DateSelectInput
- Defined in:
- lib/template_form/date_select_input.rb
Constant Summary collapse
- OPTION_KEYS =
%i[ use_month_numbers use_two_digit_numbers use_short_month add_month_numbers use_month_names month_format_string date_separator time_separator datetime_separator start_year end_year year_format day_format discard_day discard_month discard_year order include_blank default selected disabled prompt with_css_classes use_hidden ]
Instance Method Summary collapse
-
#initialize(builder, attribute_name, options) ⇒ DateSelectInput
constructor
A new instance of DateSelectInput.
- #render ⇒ Object
Constructor Details
#initialize(builder, attribute_name, options) ⇒ DateSelectInput
Returns a new instance of DateSelectInput.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/template_form/date_select_input.rb', line 33 def initialize(builder, attribute_name, ) @builder = builder @attribute_name = attribute_name @view = .delete(:view) @form_type = .delete(:form_type) || builder.form_type # Use the `:label` option to override the default label text. # Use `label: false` to indicate no label should be shown (check `has_label` in the template). @has_label = !(.has_key?(:label) && [:label] == false) @label_text = .delete(:label) || '' @label_options = Hash.new { |h,k| h[k] = '' }.update(.delete(:label_options) || {}) @hint_text = .delete(:hint) || '' data_attributes = (.delete(:data) || {}).transform_keys { |k| "data-#{k}" } @options, @html_options = .partition { |k,_| OPTION_KEYS.include? k }.map(&:to_h) @html_options.merge! data_attributes @html_options[:class] ||= '' end |
Instance Method Details
#render ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/template_form/date_select_input.rb', line 56 def render template.render( builder, attribute_name: attribute_name, view: view, has_label: has_label, label_text: label_text, label_options: , hint_text: hint_text, options: , html_options: , errors: errors, ).html_safe end |