我有一个表单需要调用日期选择器:
...
<%= f.input :expiration_date, as: :datepicker, required: false %>
...
简单表单包装器: app/inputs/datepicker_input.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
当页面从头开始加载时($(document).ready事件),会生成以下html:
<input class="datepicker optional form-control hasDatepicker" id="order_expiration_date" name="order[expiration_date]" type="text">
然而,当使用 turbolinks(通过侧边栏,“page:load”事件加载页面)加载页面时,渲染的 HTML 如下:
<input class="datepicker optional form-control" id="order_expiration_date" name="order[expiration_date]" type="text">
当然,我可以在.html.erb文件或application.js文件中简单地添加hasDatepicker类,但我想知道是否可能通过Rails功能来实现它。
page:load ready
对我没有起作用。 反而page:change
起了作用。 - Anwarwrapper_options
输入的自定义输入。这是一个更新版本的datepicker_input.rb
,支持包装器:https://gist.github.com/shrmnk/e5577b2a2176193cfbd6b92462cf5923 - shrmn