Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert Rails style date input to jQuery Tools' dateinput
// Based on
$.tools.dateinput.localize("ja", {
months: '1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月',
shortMonths: '1月,2月,3月,4月,5月,6月,7月,8月,9月,10月,11月,12月',
days: '日曜日,月曜日,火曜日,水曜日,木曜日,金曜日,土曜日',
shortDays: '日,月,火,水,木,金,土'
$.tools.dateinput.conf.format = 'yyyy-mm-dd';
$(document).ready(function() {
$.tools.dateinput.conf.lang = $('html').attr('lang');
$(', div.datetime').each(function(i, el) {
var sels = $(el).find("select:lt(3)");
var d = new Date(sels[0].value, parseInt(sels[1].value) - 1, sels[2].value);
var dateinput = $("<input type='date'>").dateinput({ value: d} );
// Without this, the field is initially blank
dateinput.change(function(event, date) {
$(sels[1]).val(date.getMonth() + 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment