At the moment, the date picker plugin
(http://kelvinluck.com/assets/jquery/datePicker/) uses an anchor added
after the input to show the calendar. What I wanted to do is show it
when I clicked on the input instead.

Also I think it is good practice to add events after adding an element
to the DOM (adding before can cause memory leaks in IE IIRC), so I
have made another tweak to do that.

The fix is as follows (applied to the uncompressed version):

jQuery.fn.datePicker = function(a)
{
        this.each(function() {
                if(this.nodeName.toLowerCase() != 'input') return;
                jQuery.datePicker.setDateWindow(this, a);
                if (!jQuery.datePicker.isInited(this)) {
                        var chooseDate = jQuery.datePicker.getChooseDateStr();
                        var calBut;
                        if(a && a.inputClick){
                                calBut = 
jQuery(this).attr({'class':'date-picker', 'title':chooseDate})
                        }
                        else {
                                calBut = 
jQuery("<a>").attr({'href':'javascript:;',
'class':'date-picker', 'title':chooseDate})
                                .append("<span>" + chooseDate + "</span>");
                        }
                        jQuery(this).wrap(
                                '<div class="date-picker-holder"></div>'
                        ).before(
                                jQuery("<div>").attr({'class':'popup-calendar'})
                        ).after(
                                calBut
                        );
                        calBut.click(jQuery.datePicker.show);
                        jQuery.datePicker.setInited(this);
                }
        });
        
};

To use:
$('input#date1').datePicker({inputClick: true});

i.e. add 'inputClick: true' as an option to show the picker when you
click on the input box containing the date.

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to