datepicker 不发送其他形式的值
datepicker not sending value with rest of form
我曾经使用 'ui_datepicker-rails3' gem 来处理我的日期选择器,但后来停用它以最终将事情转移到 rails 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 => text 并输入日期,就可以了。我注释掉字段类型(因此它默认为 3 select 日期组合)它也有效。
用于完成的咖啡脚本
$ ->
$("#job_booked_date").datepicker({
dateFormat: "dd MM yy",
minDate: 0
});
什么给了?当我选择日期时,这些值似乎在那里,但它没有在表单提交中发送。
我已经弄明白了,多亏了 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
删除“-alt”部分后,功能已恢复正常
class DatepickerInput < SimpleForm::Inputs::Base
def input
@builder.text_field(attribute_name, input_html_options)
end
end
我有不止一个#job_booked_date(而且,就此而言,每隔一个日期选择器 ID 都会被复制)
我曾经使用 'ui_datepicker-rails3' gem 来处理我的日期选择器,但后来停用它以最终将事情转移到 rails 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 => text 并输入日期,就可以了。我注释掉字段类型(因此它默认为 3 select 日期组合)它也有效。
用于完成的咖啡脚本
$ ->
$("#job_booked_date").datepicker({
dateFormat: "dd MM yy",
minDate: 0
});
什么给了?当我选择日期时,这些值似乎在那里,但它没有在表单提交中发送。
我已经弄明白了,多亏了 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
删除“-alt”部分后,功能已恢复正常
class DatepickerInput < SimpleForm::Inputs::Base
def input
@builder.text_field(attribute_name, input_html_options)
end
end
我有不止一个#job_booked_date(而且,就此而言,每隔一个日期选择器 ID 都会被复制)