简体   繁体   English

将jQuery datepicker与Chronic一起使用

[英]Using jQuery datepicker with Chronic

I'm trying to get a nice combination working for the strengths of the jQuery datepicker, and Chronic date parser for Ruby on Rails. 我试图获得一个很好的组合,以利用jQuery datepicker和Ruby on Rails的慢性日期解析器的优势。

The jQuery UI date picker is useful for selecting a date visually. jQuery UI日期选择器对于可视地选择日期很有用。 But I would also like the user to be able to type dates in, in whatever format they choose, and let the Chronic library deal with the input. 但是我也希望用户能够以他们选择的任何格式输入日期,并让Chronic库处理输入。

I've got a text input field, to which I am attaching a date picker, and the date picking functionality works great. 我有一个文本输入字段,我要附加一个日期选择器,并且日期选择功能很好用。 But what I would also like is if the user ignores the date picker, and just types in 'last tuesday' and hits enter, I would like to submit 'last tuesday' and let chronic parse that to 2011-10-18. 但是,我还想说的是,如果用户忽略日期选择器,而只输入“最后一个星期二”,然后输入点击数,我想提交“最后一个星期二”并将其长期解析到2011-10-18。 What is happening though is that the textbox value is replaced with the current date from the date picker. 但是,发生的事情是文本框值被日期选择器中的当前日期替换。

It seems like an option that should be there, to allow the date picker to work as a helper, not the sole source of input. 似乎应该有一个选择,允许日期选择器充当帮助程序,而不是唯一的输入来源。 But I can't find a way to disable this functionality. 但是我找不到禁用此功能的方法。

UPDATE: 更新:

I've got an improvement by only showing the calendar on a button press, instead of on focus, but still, it seems wrong, even if you've shown the date picker, that if you type in some text and hit enter, that gets overwritten by the date picker date! 通过仅按按钮显示日历而不是集中显示日历,我有了一个改进,但是,即使您已经显示了日期选择器,如果您键入一些文本并按Enter键,那似乎还是错的被日期选择器日期覆盖!

  $('.dl_input_production_date').datepicker({
    showOn: 'button',
    buttonImage: '/images/calendar.gif',
    buttonImageOnly: true
  });

Got an answer elsewhere: just hide the datepicker on keydown for the original input box. 在其他地方得到答案:只需隐藏原始输入框的按键时的日期选择器即可。 This means that on starting typing, the datepicker vanishes, and the typed input is used directly. 这意味着在开始键入时,日期选择器将消失,并且直接使用键入的输入。

  $('.dl_input_production_date').datepicker({
    showOn: 'button',
    buttonImage: '/images/calendar.gif',
    buttonImageOnly: true
  }).keydown( function() {
    $(this).datepicker( "hide" );
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM