Tuesday, March 1, 2011

Accessing options in jQuery Datapicker

How can I access options that I set in a jQuery Datepicker?

$("#testDatePicker").datepicker({
    minDate: new Date(2005, 0, 26),
    showOn: 'button',
    buttonImage: 'js/themes/default/images/calendar.gif',
    buttonImageOnly: true
    });
var minDate = $("#testDatePicker").?????;
From stackoverflow
  • I'd take a look at the code. Most plugins I've looked at have either a option or config var that they extend with what you pass in.

    You could check real quick and try to do something like $.datepicker.buttonImageOnly = false; and then see if that actually changed anything.

    Of course this may not work. I haven't looked at the plugin. I'm just operating off of what I see as typical behavior of plugins I've worked with (tablesorter, etc)

    JPero : Tried the $.datepicker.buttonImageOnly = false;, no go. =(
  • What about storing the options in a named var instead of an anonymous object?

    var dpOptions = {minDate: new Date(2005, 0, 26), ...};
    $('#testDatePicker').datepicker(dpOptions);
    .
    .
    .
    var minDate = dpOptions.minDate;
    
    JPero : I think something like that is going to be my work around if the items aren't accessible directly, but if the testDatePicker already has these values, I'd rather access them through that object. I'd think they'd have to be in there somewhere, it's just a matter of accessing them.
  • If you don't have enough with @mausch solution the settings are stored here:

     $.data($('#testDatePicker')[0], 'datepicker').settings
    

0 comments:

Post a Comment