Sha256: dbb1fd90ab2f8ef0cfd43f530d31d4cc53b40f447d51bfda6b6e9e6a96ee28a9

Contents?: true

Size: 842 Bytes

Versions: 4

Compression:

Stored size: 842 Bytes

Contents

# frozen_string_literal: true

module Eac
  module CommonFormHelper
    class FormBuilder
      module YearMonthField
        def year_month_field(field_name, options = {})
          field(field_name, options) do
            month_field(field_name) << ' / ' << year_field(field_name,
                                                           options[:years] || default_years)
          end
        end

        private

        def year_field(field_name, years)
          form.select("#{field_name}_year", years.map { |y| [y, y] })
        end

        def month_field(field_name)
          form.select("#{field_name}_month", (1..12).map { |y| [y.to_s.rjust(2, '0'), y] })
        end

        def default_years
          current_year = Time.zone.now.year
          ((current_year - 5)..current_year)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eac_rails_utils-0.10.1 lib/eac/common_form_helper/form_builder/year_month_field.rb
eac_rails_utils-0.10.0 lib/eac/common_form_helper/form_builder/year_month_field.rb
eac_rails_utils-0.9.1 lib/eac/common_form_helper/form_builder/year_month_field.rb
eac_rails_utils-0.9.0 lib/eac/common_form_helper/form_builder/year_month_field.rb