Question

I need to adjust a date selected in jQuery's datepicker. For example, whatever user chooses, change to closest weekend.

Is there a way to do this? Some validation / filtering support. Or maybe it can be done with a help from some other validation library that will track text in the text box, not the datepicker value?

Was it helpful?

Solution

What you can do is subscribe to the select event and change the date:

$('.selector').datepicker({
    onSelect: function(dateText, inst) {
        var date = $(inst).datepicker('getDate'); // Date should be a Date object
        // do some calculation and set the date via:
        $(inst).datepicker('setDate', date);
    }
});

Note: not tested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top