Module: Formize::Helpers::FormTagHelper
- Defined in:
- lib/formize/helpers/form_tag_helper.rb
Instance Method Summary collapse
- #date_field_tag(name, value = nil, options = {}) ⇒ Object
-
#datetime_field_tag(name, value = nil, options = {}) ⇒ Object
Returns a text field with a default placeholder for timestamp.
Instance Method Details
#date_field_tag(name, value = nil, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/formize/helpers/form_tag_helper.rb', line 6 def date_field_tag(name, value=nil, ={}) format = [: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)} name_id = name.to_s.gsub(/[^a-z]+/, '_') html = "" html << hidden_field_tag(name, (value.is_a?(Date) ? value.to_s(:db) : value.to_s), :id => name_id) html << tag(:input, :type=>:text, "data-datepicker" => name_id, "data-date-format" => format, :value => localized_value, "data-locale" => ::I18n.locale, :size => .delete(:size)||10) return html.html_safe end |
#datetime_field_tag(name, value = nil, options = {}) ⇒ Object
Returns a text field with a default placeholder for timestamp
22 23 24 25 26 27 |
# File 'lib/formize/helpers/form_tag_helper.rb', line 22 def datetime_field_tag(name, value=nil, ={}) default = {} default[:placeholder] = I18n.translate!('time.placeholder') rescue nil default[:size] ||= 24 return text_field_tag(name, value, default.merge()) end |