Sha256: 8b06c68b91b8f073986a33395491ca02f37847699fa71a2895ad3c72e56ddfdb

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

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

      def default_input_js
        { format: 'HH:mm', showClear: true, useCurrent: 'hour' }
      end

      def default_input_html
        {class: 'effective_time_picker time'}
      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-time').html_safe
          end +
          text_field_tag(field_name, value, tag_options)
        end
      end

      def value
        val = super
        val.respond_to?(:strftime) ? val.strftime('%H:%M') : 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{2}:\d{2}' # Match default pattern defined above
          end

          if options[:date_linked] == false
            html_options[:class] << 'not-date-linked'
          end

        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
effective_form_inputs-1.2.4 app/models/inputs/effective_time_picker/input.rb
effective_form_inputs-1.2.3 app/models/inputs/effective_time_picker/input.rb
effective_form_inputs-1.2.2 app/models/inputs/effective_time_picker/input.rb
effective_form_inputs-1.2.1 app/models/inputs/effective_time_picker/input.rb
effective_form_inputs-1.2.0 app/models/inputs/effective_time_picker/input.rb