read = ->
$('#date_picker').datepicker
$(document).ready read
$(document).on "page:load", read
我使用上面的代码是我如何调用datepicker。我正在使用日期选择器rails gem。以下是表格代码
= simple_form_for :due_on,:url=> admin_requests_path,:method => "get",html: {id: "due_on_filter"} do |f|
= f.input :mydate,:disabled => 'disable', :input_html => { :data => {:behaviour => :datepicker },id: "date_picker"}
我无法让它发挥作用。没有错误但是datepicker不起作用。
这是我的application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require jquery.ui.core
//= require jquery_nested_form
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap3
//= require datatable_calls
//= require nprogress
//= require nprogress-turbolinks
//= require chosen-jquery
//= require chosen_calls
//= require filter_ajax_calls
//= require bootstrap-datepicker/core
//= require custom
表单的HTML原始输出是:
<form accept-charset="UTF-8" action="/admin/requests" class="simple_form due_on" id="due_on_filter" method="get" novalidate="novalidate">
<div style="display:none"><input name="utf8" type="hidden" value="✓" /></div>
<div class="control-group string required due_on_mydate">
<label class="string required control-label" for="date_picker">
<abbr title="required">*</abbr> Mydate</label>
<div class="controls">
<input class="string required" data-behaviour="datepicker" id="date_picker" name="due_on[mydate]" type="text" />
</div>
</div>
</form>
答案 0 :(得分:3)
你确定这个js / coffee代码有效吗?
你可以试试吗:
setInterval(function() {
$(function () {
var datepicker = $('#date_picker');
if(datepicker.length) {
datepicker.datepicker();
alert("found the element!");
} else {
alert("could not find element");
}
});
}, 4000);
答案 1 :(得分:1)
在脚本中编辑为
$(function(){$("#datepicker").datepicker({
showbuttonPanel: true
});
});
您需要在js和amp;中同时需要bootstrap
和jquery-ui-1.10.4.custom
个文件。 css应用程序。现在使用datepicker id实现datepicker。