Question

I'm trying to get a nice combination working for the strengths of the jQuery datepicker, and Chronic date parser for Ruby on Rails.

The jQuery UI date picker is useful for selecting a date visually. 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.

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. 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!

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

Solution

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" );
  });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top