在结帐时,我提示用户确认他的地址和required_date
接收部件。下面显示了需要确认的@auction
属性的表单。所有的地址行都已经填满了。但是日期字段被清除,我希望日期字段用已经选择的日期(@auction.required_date
)填充,这样如果required_date
没有改变,用户就不必重新选择日期。
这是表单
.form-container
%p#alert= alert
= form_for(@auction, html: { class: "inline-form" }, remote: true ) do |f|
- if @auction.errors.any?
#error_explanation
%h2
= pluralize(@auction.errors.count, "error")
prohibited this auction from being saved:
%ul
- @auction.errors.full_messages.each do |message|
%li= message
.field.form-group
= f.text_field :destination_address, class: "form-control", placeholder: "Destination Street Address"
.field.form-group
= f.text_field :destination_city, class: "form-control", placeholder: "Destination City"
.field.form-group
= f.text_field :destination_state, class: "form-control", placeholder: "Destination State/Region"
.field.form-group
= f.text_field :destination_zip, class: "form-control", placeholder: "Destination Zip Code"
.field.form-group
= f.text_field :destination_country, class: "form-control", placeholder: "Destination Country"
.field
= f.date_field :required_date, class: "form-control datepicker", placeholder: "Required Delivery Date"
%br/
.actions.submit_button
= f.submit 'Submit', class: "btn custom-btn"
%br/
:javascript
$('.datepicker').pickadate({
selectMonths: true
});
我相信你可以这样做:
= f.date_field :required_date, class: "form-control datepicker", placeholder: "Required Delivery Date", value: @auction.required_date
,它应该填充日期字段。
我想你必须使用strftime以正确的格式添加值,例如:
value: @auction.required_date.strftime('%m/%d/%Y')