0

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?

3 Answers 3

1

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/

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

This doesn't work, it still defaults back to today after you select something
1

You can apply date-picker to some other textfield and whenever date is selected you can modify your textfield content.

1 Comment

This would work, but i'd rather not have unnecessary text fields all over my code. If there's another way around this it would be preferable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.