Sha256: 61455e7ae27ae620cfbd35723acfc5e1eb06c0089771a4c93c1345c0732862ca

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

module Formize
  module Helpers
    module FormTagHelper


      def date_field_tag(name, value=nil, options={})
        format = options[:format]||:default
        raise ArgumentError.new("Option :format must be a Symbol referencing a translation 'date.formats.<format>'")unless format.is_a?(Symbol)
        unless (localized_value = value).nil?
          localized_value = I18n.localize(localized_value, :format=>format)
        end
        format = I18n.translate('date.formats.'+format.to_s)
        Formize::DATE_FORMAT_TOKENS.each{|js, rb| format.gsub!(rb, js)}        
        html  = ""
        html << hidden_field_tag(name, (value.is_a?(Date) ? value.to_s(:db) : value.to_s))
        html << tag(:input, :type=>:text, "data-datepicker"=>name, "data-date-format"=>format, :value=>localized_value, "data-locale"=>::I18n.locale, :size=>options.delete(:size)||10)
        return html.html_safe
      end

      # Returns a text field with a default placeholder for timestamp
      def datetime_field_tag(name, value=nil, options={})
        default = {}
        default[:placeholder] = I18n.translate!('time.placeholder') rescue nil
        default[:size] ||= 24
        return text_field_tag(name, value, default.merge(options))
      end


    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
formize-0.0.27 lib/formize/helpers/form_tag_helper.rb
formize-0.0.26 lib/formize/helpers/form_tag_helper.rb
formize-0.0.25 lib/formize/helpers/form_tag_helper.rb
formize-0.0.24 lib/formize/helpers/form_tag_helper.rb
formize-0.0.23 lib/formize/helpers/form_tag_helper.rb
formize-0.0.22 lib/formize/helpers/form_tag_helper.rb
formize-0.0.21 lib/formize/helpers/form_tag_helper.rb
formize-0.0.20 lib/formize/helpers/form_tag_helper.rb