Reputation: 12998
I have a jquery datepicker which selects week number and a date range based on what date is picked.
$("input").datepicker({
onSelect: function(dateText, inst) {
$(this).val("Week Number " + $.datepicker.iso8601Week(new Date(dateText)) + " • " + $.datepicker.formatDate('d M', new Date(dateText)) + " - " + $.datepicker.formatDate('d M yy', new Date(new Date(dateText).getTime() + 6*24*60*60*1000)));
}
});
The trouble is, by formatting the date using this method, it prevents the datepicker from defaulting to the selected date when you click the input again. It defaults to the current date.
I have to use this method due to some of the other code I am using (I've avoided showing this because it's long and not relevant to this problem).
Any ideas how I can get it to default to the previously selected date?
Upvotes: 0
Views: 2416
Reputation: 16403
Add the following line to the function that will be called for the onSelect
event
$.datepicker.setDefaults({"defaultDate":dateText});
See http://jsfiddle.net/ELXGP/5/
Upvotes: 1
Reputation: 172
You can apply date-picker to some other textfield and whenever date is selected you can modify your textfield content.
Upvotes: 1
Reputation: 14286
You can always set the date "by hand" calling the:
.datepicker("setDate", defaultDate);
method. But prior to that take a look at the wast number of properties you can set to the datepicker, maybe one of the will solve your problem.
Upvotes: 1