Module: JqueryDatetimepick::FormHelper
- Includes:
- ActionView::Helpers::JavaScriptHelper
- Included in:
- DatetimepickHelper
- Defined in:
- lib/jquery_datetimepick/form_helper.rb
Instance Method Summary collapse
-
#datetimepicker(object_name, method, options = {}) ⇒ Object
Mehtod that generates datetimepicker input field inside a form.
Instance Method Details
#datetimepicker(object_name, method, options = {}) ⇒ Object
Mehtod that generates datetimepicker input field inside a form
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jquery_datetimepick/form_helper.rb', line 9 def datetimepicker(object_name, method, = {}) input_tag = JqueryDatetimepick::InstanceTag.new(object_name, method, self, ) , = input_tag.() [:value] = input_tag.format_datetime([:value], String.new([:dateFormat])) if [:value] && ![:value].empty? && .has_key?(:dateFormat) [ :minDateTime, :maxDateTime ].each do |var| if(o = [var]) if o.respond_to?(:strftime) [var] = "new Date(#{o.to_i*1000})" else [var] = "function() { return #{o}; }" end end end json = .to_json json.gsub! /"(new Date\([^\)]*\))"/, '\1' json.gsub! /"(function\(\) \{[^\}]*\})"/, '\1' html= if defined?(ActionView::Helpers::InstanceTag) && ActionView::Helpers::InstanceTag.instance_method(:initialize).arity != 0 input_tag.to_input_field_tag("text", ) else ActionView::Helpers::Tags::TextField.new(object_name, method, ).render end html += javascript_tag("jQuery(document).ready(function(){jQuery('##{input_tag.get_name_and_id["id"]}').datetimepicker($.extend(#{json}, $.timepicker.regional[#{I18n.locale}]))});") html.html_safe end |