Sha256: 1dd056c7ba7edb580bc7fe59ef4d980925ee9f30c2c9ce4841b10787b5d9ac5f

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module DatePicker
  module FormHelper
    
    def self.field_id(object_name, attribute)
      object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"") + "_" + attribute.to_s
    end
    
    def self.included(base)
      ActionView::Helpers::FormBuilder.instance_eval do
        include FormBuilderMethods
      end
    end
    
    module FormBuilderMethods
      
      def date_picker(attribute, options = {}, html_options = {})
        html_options[:id]||= DatePicker::FormHelper.field_id(self.object_name, attribute)
        @template.date_picker_tag("#{self.object_name}[#{attribute}]", self.object.send(attribute), options, html_options)
      end
      
      def datetime_picker(attribute, options = {}, html_options = {})
        html_options[:id]||= DatePicker::FormHelper.field_id(self.object_name, attribute)
        @template.datetime_picker_tag("#{self.object_name}[#{attribute}]", self.object.send(attribute), options, html_options)
      end
      
      def time_picker(attribute, options = {}, html_options = {})
        html_options[:id]||= DatePicker::FormHelper.field_id(self.object_name, attribute)
        @template.time_picker_tag("#{self.object_name}[#{attribute}]", self.object.send(attribute), options, html_options)
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
date_picker-0.0.9 lib/date_picker/form_helper.rb