Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align Datepicker to text box right edge?

I have jQuery UI Datepicker on the top right edge of my layout.
By default, it opens aligned to the left edge of its text box.
Thus, it falls out of the layout:

Date Picker

How to make it open aligned to the right border of its text box?

like image 742
Michał Pękała Avatar asked Jun 17 '10 09:06

Michał Pękała


2 Answers

It took me a while to figure this out.

$('.date').datepicker({
    beforeShow: function(input, inst) {
        var widget = $(inst).datepicker('widget');
        widget.css('margin-left', $(input).outerWidth() - widget.outerWidth());
    }
});
like image 66
Alex Barker Avatar answered Sep 18 '22 21:09

Alex Barker


I know it's an old question... but still not native solution... here's an updated piece of code:

$('.datepicker').datepicker({
    beforeShow:function( input, inst )
    {
        var dp = $(inst.dpDiv);
        var offset = $(input).outerWidth(false) - dp.outerWidth(false);
        dp.css('margin-left', offset);
    }
});
like image 30
Bradley Avatar answered Sep 20 '22 21:09

Bradley