Sha256: 70fc2ba7c4c2f5401d80fcbfc1029395e5c374121c00df9684102b01da1cd327

Contents?: true

Size: 1.51 KB

Versions: 14

Compression:

Stored size: 1.51 KB

Contents

class DateTimeInput < SimpleForm::Inputs::Base
  def input(wrapper_options)
    date_format = options[:date_format] || '%m/%d/%Y'
    raw_value = object.public_send(attribute_name)
    raw_value = raw_value.strftime(date_format) if raw_value.present?

    disabled = options[:disabled] || false

    hash = { id: "#{attribute_name}_datetimepicker", class: 'form-control', value: raw_value, disabled: disabled, 'data-toggle': 'datetimepicker', 'data-target': "##{attribute_name}_datetimepicker" }
    data = options[:data] || {}
    data.keys.each do |d|
      hash["data-#{d.to_s.dasherize}".to_sym] = data[d]
    end
    field = @builder.text_field(attribute_name, hash)

    add_on_class = options[:add_on_class] || "fa fa-calendar"

    add_on = template.content_tag(:div, class: "input-group-prepend") do
      add_on = template.content_tag(:div, class: "input-group-text") do
        hash = { class: add_on_class, 'data-toggle': 'datetimepicker', 'data-target': "##{attribute_name}_datetimepicker" }
        template.content_tag(:i, '', hash)
      end
    end

    all = content_tag(:div, add_on + field, class: 'input-group')

    script = "".html_safe
    unless disabled then
      picker_options = options[:picker_options] || { "format" => "MM/DD/YYYY" }

      script = """
        <script>
        $(document).ready(function() {
          $('##{attribute_name}_datetimepicker').datetimepicker(
            #{picker_options.to_json}
          );
        });
        </script>
      """.html_safe
    end

    all + script
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
five-two-nw-olivander-0.2.0.30 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.29 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.28 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.27 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.26 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.25 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.24 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.23 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.22 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.19 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.18 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.17 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.16 app/inputs/date_time_input.rb
five-two-nw-olivander-0.2.0.15 app/inputs/date_time_input.rb