Sha256: e70d746a045a4ed9e0b593267f01d87046427c1dd3dafb55f5ca87fddc9dbd7f

Contents?: true

Size: 1.12 KB

Versions: 11

Compression:

Stored size: 1.12 KB

Contents

module Inputs
  module EffectiveDatePicker
    class Input < Effective::FormInput
      delegate :content_tag, :text_field_tag, :to => :@template

      def default_input_js
        {:format => 'YYYY-MM-DD'}
      end

      def default_input_html
        {class: 'effective_date_picker date'}
      end

      def to_html
        if options[:input_group] == false
          return text_field_tag(field_name, value, tag_options)
        end

        content_tag(:div, class: 'input-group') do
          content_tag(:span, class: 'input-group-addon') do
            content_tag(:i, '', class: 'glyphicon glyphicon-calendar').html_safe
          end +
          text_field_tag(field_name, value, tag_options)
        end
      end

      def value
        val = super
        val.kind_of?(Time) ? val.to_date : val
      end

      def html_options
        super.tap do |html_options|
          if js_options[:format] == default_input_js[:format] # Unless someone changed from the default
            html_options[:pattern] = '\d{4}(-\d{2})?(-\d{2})?' # Match default pattern defined above
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
effective_form_inputs-1.0.2 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-1.0.1 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-1.0.0 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-0.9.8 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-0.9.7 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-0.9.6 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-0.9.5 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-0.9.4 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-0.9.3 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-0.9.2 app/models/inputs/effective_date_picker/input.rb
effective_form_inputs-0.9.1 app/models/inputs/effective_date_picker/input.rb