Sha256: e6ba1639efac164dd43a8028ef92cbf41426d120a9fbd3a4b55bb7621cb77921

Contents?: true

Size: 852 Bytes

Versions: 28

Compression:

Stored size: 852 Bytes

Contents

module CustomAttributes
  class DateFieldType < Unbounded
    include Singleton

    def cast_single_value(_custom_field, value, _customized = nil)
      value.to_date
    rescue
      nil
    end

    def validate_single_value(_custom_field, value, _customizable = nil)
      if value =~ /^\d{4}-\d{2}-\d{2}$/ && (begin
                                              value.to_date
                                            rescue
                                              false
                                            end)
        []
      else
        [::I18n.t('activerecord.errors.messages.not_a_date')]
      end
    end

    def edit_tag(view, tag_id, tag_name, custom_value, options = {})
      view.date_field_tag(tag_name, custom_value.value, options.merge(id: tag_id, size: 10)) +
        view.calendar_for(tag_id)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
create_custom_attributes-0.6.3 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.6.2 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.6.1 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.25 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.24 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.23 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.22 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.21 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.20 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.19 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.18 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.17 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.16 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.15 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.14 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.13 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.12 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.11 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.10 lib/custom_attributes/field_types/date_field_type.rb
create_custom_attributes-0.5.9 lib/custom_attributes/field_types/date_field_type.rb