rails-bootstrap-formsを使っていてbootstrap-datetimepickerを使ったメモ書きです。
cdn経由でcssとjsを指定するのでコピペで動きます。
Bootstrap datetimepicker Date/time picker widget for Twitter Bootstrap v3
http://eonasdan.github.io/bootstrap-datetimepicker/
Moment.js
http://momentjs.com/
cssとjavascriptの読み込み。
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.0.0/css/bootstrap-datetimepicker.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.6.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.6.0/lang/ja.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.0.0/js/bootstrap-datetimepicker.min.js"></script>
フィールドはこんな感じ。
<%= f.date_field :date %>
<%= f.time_field :start_time %>
date-pickerとtime-pickerを別々に。
$(document).ready(function() {
$.fn.datetimepicker.dates = {
ja: {
days: ["日曜", "月曜", "火曜", "水曜", "木曜", "金曜", "土曜", "日曜"],
daysShort: ["日", "月", "火", "水", "木", "金", "土", "日"],
daysMin: ["日", "月", "火", "水", "木", "金", "土", "日"],
months: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
monthsShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"]
}
};
$('input[type=date]').datetimepicker({
format: 'YYYY-MM-DD',
language: 'ja',
autoclose: 'true',
pickTime: false,
});
$('input[type=time]').datetimepicker({
format: "HH:mm",
language: 'ja',
autoclose: 'true',
minuteStepping:10,
pickDate: false,
});
});
rails-bootstrap-formsはこれ。
https://github.com/bootstrap-ruby/rails-bootstrap-forms