0
我目前使用Ryan Bates https://github.com/ryanb/nested_form的嵌套表格gem,併爲我的某個字段實現了bootstrap-datepicker-rails https://github.com/Nerian/bootstrap-datepicker-rails。帶有嵌套表格的日期選擇器編輯
當添加新記錄時,此工作正常。我遇到的問題是使用嵌套窗體編輯記錄時使datepicker工作。
我已經添加了建議javascript來我的應用程序啓動時,一個新的領域(記錄)想要加入
$(document).on('nested:fieldAdded', function(event){
// this field was just inserted into your form
var field = event.field;
// it's a jQuery object already! Now you can find date input
var dateField = field.find('.datepicker');
// and activate datepicker on it
dateField.datepicker(
{
"format": 'yyyy-mm-dd',
"autoclose": true,
"placement": 'right'
}
);
})
嵌套表格場塊
<%= f.fields_for :weeks do |week_form| %>
<%= week_form.grouped_collection_select :product_id, @locations, :products, :name, :id, :name, :prompt => "Select Location" %>
<%= week_form.text_field :start_at, class: 'datepicker' %>
<%= week_form.text_field :end_at, class: 'datepicker' %>
<%= week_form.link_to_remove "Remove this task" %>
<% end %>
<p><%= f.link_to_add "Add a Week to Campaign", :weeks %></p>
誰能幫助日期選擇器我在編輯記錄的時候如何讓這個功能起作用?
TIA
使用此代碼我得到一個錯誤; ReferenceError:未定義事件 \t field = event.field; – hso