Sha256: a7eefa479517530c050a774e8cc2daa2879a0793f235563f0d51254dc6797ede

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 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 = {})
        options[:id]||= DatePicker::FormHelper.field_id(self.object_name, attribute)
        @template.date_picker_tag("#{self.object_name}[#{attribute}]", self.object.send(attribute), options)
      end
      
      def datetime_picker(attribute, options = {})
        options[:id]||= DatePicker::FormHelper.field_id(self.object_name, attribute)
        @template.datetime_picker_tag("#{self.object_name}[#{attribute}]", self.object.send(attribute), options)
      end
      
      def time_picker(attribute, options = {})
        options[:id]||= DatePicker::FormHelper.field_id(self.object_name, attribute)
        @template.time_picker_tag("#{self.object_name}[#{attribute}]", self.object.send(attribute), options)
      end
      
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
date_picker-0.0.8 lib/date_picker/form_helper.rb
date_picker-0.0.7 lib/date_picker/form_helper.rb
date_picker-0.0.6 lib/date_picker/form_helper.rb
date_picker-0.0.5 lib/date_picker/form_helper.rb
date_picker-0.0.4 lib/date_picker/form_helper.rb
date_picker-0.0.3 lib/date_picker/form_helper.rb
date_picker-0.0.2 lib/date_picker/form_helper.rb
date_picker-0.0.1 lib/date_picker/form_helper.rb