I'm trying to change my simple form default date format to jQuery datepicker on an events site I'm building. I've followed Ryan Bates' video but no joy. Here's my code -
Application.js
//= require jquery
//= require jquery_ujs
//= require jquery-ui/datepicker
//= require turbolinks
//= require_tree .
Events.coffee
jQuery ->
$("#datepicker").datepicker(
dateFormat: "DD-mm-yy"
);
Form -
<%= f.input :image, as: :file, label: 'Image' %>
<%= f.input :title, label: 'Title' %>
<%= f.input :location, label: 'Location' %>
<%= f.text_field :date, label: 'Date' %>
<%= f.input :time, label: 'Time' %>
<%= f.input :description, label: 'Description' %>
<%= f.input :organised_by, label: 'Organised by' %>
<%= f.input :organiser_description, label: 'Organiser description' %>
<%= f.input :url, label: "Link to Organiser site" %>
My Events Controller has the following method -
def new
@event = current_user.events.build
end
I'm not sure if #current_user.events.build is what needs to be shown in the jQuery function. I'm obviously not identifying the element properly. Any help would be appreciated.
您需要为表单字段分配一个id
,以便日期选择器出现。
<%= f.text_field :date, id: 'datepicker', label: 'Date' %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.