可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I finally found a suitable fix:
app/inputs/datepicker_input.rb is left the same, the wrapper works nice.
assets/javascripts/application.js
//= require jquery //= require jquery_ujs //= require turbolinks //= require bootstrap.js //= require_tree . $(document).on("page:load ready", function(){ $("input.datepicker").datepicker(); });
Since :datepicker input type adds ".datepicker" class to rendered HTML, it's enough just to bind datepicker() to all elements with that class. It does the trick with the least amount of code.
It's important to specify "input.datepicker" since the ".datepicker" class is added both to label and input tags.
turbolinks throws a page:load event, so I've added handler for both cases - when the page loads with turbolinks, and when it loads from scratch (window refresh, link saved in favourites, etc)
Now the following .html.erb is rendered as I expect:
'Select date', input_html: {class: "form-control"}, label: "Expiration date: " %>
output:
回答2:
The following works for me in simple_form
and jquery-ui
:
js:
$('input#date_field').datepicker();
form:
'Select Date' %>
So without as: :datepicker
.
回答3:
Try this:
'Select Expiration Date' %>
Javascript
$(document).ready(function() { $('#order_expiration_date').datepicker({ changeMonth: true, changeYear: true, yearRange: '-70:-18' }); });
app/assets/javascript/application.js should be
//= require jquery //= require jquery.turbolinks //= require jquery_ujs //= require jquery.ui.all //= require turbolinks