Reputation: 4755
Scenario: A humble text field, marked as readonly. When clicked a datepicker appears. When you click a date from the datepicker it populates that text field with something like: 10/05/2013.
Problem: I need to reformat the text from 10/05/2013 to Friday, May 10, 2013. To do this I need to catch when the value inside the text field is changed. This is where the problem begins. The typical events are:
change
: can't use this because it requires the text field to come OUT of focus (assuming it was in focus) before checking the difference;keyup
: can't use this because the user isn't pressing any keys o.Opaste
: no pasting being done here, not by the user at leastinput
: I was hoping this'd work, but it doesn't. I'm not actually quite sure when this event is supposed to fire, but it's not helping me here :(My code looks something like:
$('input[type="text"]').datepicker('hide');
// That sets up the datepicker (as per a plugin) to pop up
// when I click the text box, working fine :D
$('input[type="text"]').live('change keyup paste input', function() {
// Trying everything out of desperation :/
alert($(this).value());
});
Question: How can I catch when the text in this input field changes under in the scenario described?
Upvotes: 1
Views: 804
Reputation: 20250
Why can't you just set the dateFormat
?
$('input[type="text"]').datepicker({
dateFormat: 'DD, M d, yy'
});
Upvotes: 1
Reputation: 686
Try it here:
http://jsfiddle.net/Madthew/9nw3f/
and follow this: http://api.jqueryui.com/datepicker/#option-dateFormat
in order to format your date.
If you leave 'hide' here:
$('input[type="text"]').datepicker('hide');
the calendar doesn't appear.
Upvotes: 0