I need to add a class “above” or “below” to my input element depending on which side the datepicker opened on.
I just can’t seem to figure out how to get the position of the datepicker instance that’s ABOUT to be created…. maybe im just thinking about it wrong.
$('#order-main .datepicker').datepicker({
showOn: 'both',
buttonImage: 'img/icons/calendar.png',
buttonImageOnly: true,
minDate: -1,
maxDate: "+1Y",
showButtonPanel: true,
showAnim: 'slideDown',
hideIfNoPrevNext: true,
dateFormat: 'yyyy-mm-dd',
duration: 500,
beforeShow: function(input, inst) {
var pos = $(input).offset().top;
// if the top position of the to-be-created instance is < top position
//of the elemnt, its ABOVE, therefore add above, otherwise add below.
inst.dpDiv.addClass('above')
}
});
I know how to extend it using $.extend($.datepicker,{_checkOffset:function(inst,offset,isFixed){return offset}}); so it’ll always show below, but I would prefer to keep its dynamic placement functionality, but just KNOW whether its above or below, so i can style my input element properly.
Small thing, but it’d be nice to get done.
I think this is what you are looking for.
Use position instead of offset.