DateTimePicker没有更新ruby端的值

时间:2017-05-09 13:08:40

标签: javascript ruby-on-rails ruby bootstrap-datetimepicker eonasdan-datetimepicker

我遇到一个问题,即常规日期选择器以此格式'2017-09-12 22:49:27'更新rails侧的值,但我尝试使用datetimepicker并且不更新值,它会使用格式更新文本字段:M/DD/YYYY但不是param中的实际值,因为我需要'2017-09-12 22:49:27'格式,但它保持与当前MM/DD/YYYY相同的值,就像为文本字段加载的那样,我是当我尝试查看当前值时获取undefined值:

var selectedDate = $("#from").find(".active").data("day");

这是ruby代码

= text_field_tag :from_js, l((params[:from].to_datetime or @item.created_at), format: :american_no_time), class: 'form-control input-sm datetimepicker', id:  'from'
= hidden_field_tag :from, l((params[:from].to_datetime or @item.created_at), format: :american_no_time)

= text_field_tag :to_js, l((params[:to].to_datetime or Time.zone.now.to_datetime), format: :american_no_time), class: 'form-control input-sm datetimepicker', id: 'to'
= hidden_field_tag :to, l((params[:to].to_datetime or Time.zone.now.to_datetime), format: :american_no_time)

这是当前的javascript:

var maxDate = new Date();
var minDate = $("#from").val();
$(function () {
  $('#from').datetimepicker({
    format: "M/D/YYYY",
    minDate: minDate,
    maxDate: maxDate,
    pickTime: false
  });

  $('#to').datetimepicker({
    format: "M/D/YYYY",
    minDate: minDate,
    maxDate: maxDate,
    pickTime: false
  });
}); 

任何想法或建议都将不胜感激

0 个答案:

没有答案