datepicker不以其余形式发送值

时间:2015-04-22 06:54:50

标签: jquery ruby-on-rails ruby-on-rails-3 jquery-ui-datepicker simple-form

我曾经使用' ui_datepicker-rails3'宝石处理我的日期选择器,但后来退休了,最终将东西搬到了铁轨4。除了弄清楚' jquery-ui-rails','> = 5.0'很好地处理日期拣货员。

  = simple_form_for job, :url => job_path(job), :html => { :method => :put } do |f|
    = f.input :booked_date, :label => "Reschedule for", :as => :datepicker
    = f.input :job_card_id, :label => "or add to", :hint => "Job Card for today", :as => :select, :collection => @job_cards, label_method: :franchisee_name, value_method: :id, include_blank: true
    = f.input :last_message, :label => "Reason for reschedule"
.actions  
      = f.submit "Reschedule", :class => "btn btn-primary"
      = link_to "Do not reschedule", job_path(job), :class => "btn btn-secondary"

这是一个简单的表单,布局,日期选择器和一切都与以前完全一样。

有一个例外

所挑选的日期并未包含在提交的表单中。值

Processing by JobsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"x+8Lw1NMmYIIySUcp9JeTDXzGnHYqL6hCWkof6nK/0Y=", "job"=>{"booked_date"=>"", "job_card_id"=>"", "last_message"=>"jh"}, "commit"=>"Reschedule", "id"=>"1001787"}

如果我将字段类型更改为:as =>文字并输入日期,没关系。它我注释掉了字段类型(所以它默认为3选择日期组合)它也有效。

咖啡脚本完成

$ ->
  $("#job_booked_date").datepicker({
    dateFormat: "dd MM yy",
    minDate: 0
      });

是什么给出的?当我选择它们时,这些值似乎就在那里,但是它没有在表单提交中发送。

1 个答案:

答案 0 :(得分:2)

this post之前,我已经弄明白了,感谢很多不太完美的解决方案。

在使用:date_picker转换为:datepicker作为simple_form字段类型时,我必须在config / initializers / datepicker.rb中创建一个输入包装器

class DatepickerInput < SimpleForm::Inputs::Base
  def input
    @builder.text_field(attribute_name, input_html_options) + \
    @builder.hidden_field(attribute_name, { :class => attribute_name.to_s + "-alt"})
  end
end 

删除&#39; -alt&#39;部分,功能已恢复正常

class DatepickerInput < SimpleForm::Inputs::Base
  def input
    @builder.text_field(attribute_name, input_html_options)
  end
end 

我有多个#job_booked_date(就此而言,每个其他日期选择器ID都被复制)