views:

121

answers:

1

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?

A: 

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.

Emil Ivanov