The datePicker plugin[1] won't work for multiple date inputs unless you
add an id attribute to each input tag (though this restriction does not
seem to be mentioned anywhere). I didn't want to have to generate ids
for each date input on my page, so I patched datePicker to get rid of
the id requirement. I don't see anywhere on the author's page to submit
patches, so I've attached it here for anyone interested.
-- Matt Good
[1] http://kelvinluck.com/assets/jquery/datePicker/
Index: datePicker_source.js
===================================================================
--- datePicker_source.js (revision 21)
+++ datePicker_source.js (working copy)
@@ -21,9 +21,6 @@
var dateFormat = 'dd/mm/yyyy';
var _firstDate;
var _lastDate;
- var _firstDates = {};
- var _lastDates = {};
- var _inited = {};
var _selectedDate;
var _openCal;
@@ -257,10 +254,11 @@
_closeDatePicker();
}
this.blur();
- _firstDate = _firstDates[this.id];
- _lastDate = _lastDates[this.id];
+ var input = $('input', $(this).findClosestParent('input'))[0];
+ _firstDate = input._startDate;
+ _lastDate = input._endDate;
_openCal = $(this).findClosestParent('div.popup-calendar');
- var d = $('input', $(this).findClosestParent('input')).val();
+ var d = $(input).val();
if (d != '') {
if (_dateToStr(_strToDate(d)) == d) {
_selectedDate = d;
@@ -300,11 +298,11 @@
},
setInited: function(i)
{
- _inited[i] = true;
+ i._inited = true;
},
isInited: function(i)
{
- return _inited[i] != undefined;
+ return i._inited != undefined;
},
setDateFormat: function(format)
{
@@ -343,12 +341,16 @@
setDateWindow: function(i, w)
{
if (w == undefined) w = {};
- _firstDates[i] = w.startDate == undefined ? new Date() : _strToDate(w.startDate);
+ if (w.startDate == undefined) {
+ i._startDate = new Date();
+ } else {
+ i._startDate = _strToDate(w.startDate);
+ }
if (w.endDate == undefined) {
- _lastDates[i] = new Date();
- _lastDates[i].setFullYear(_lastDates[i].getFullYear()+5);
+ i._endDate = new Date();
+ i._endDate.setFullYear(i._endDate.getFullYear()+5);
} else {
- _lastDates[i] = _strToDate(w.endDate);
+ i._endDate = _strToDate(w.endDate);
};
}
};
@@ -370,10 +372,9 @@
{
this.each(function() {
if(this.nodeName.toLowerCase() != 'input') return;
- var butId = '__dp_' + this.id;
- $.datePicker.setDateWindow(butId, a);
- if (!$.datePicker.isInited(butId)) {
- var calBut = $.A({href:'javascript:;', className:'date-picker', title:'Choose date', id:butId}, $.SPAN({}, 'Choose date'));
+ $.datePicker.setDateWindow(this, a);
+ if (!$.datePicker.isInited(this)) {
+ var calBut = $.A({href:'javascript:;', className:'date-picker', title:'Choose date'}, $.SPAN({}, 'Choose date'));
$(calBut).click($.datePicker.show);
$(this).wrap(
'<div class="date-picker-holder"></div>'
@@ -382,7 +383,7 @@
).after(
calBut
);
- $.datePicker.setInited(butId)
+ $.datePicker.setInited(this);
}
});
@@ -455,4 +456,4 @@
<div class="link-prev"><a href="#">Prev</a></div>
<div class="link-next"><a href="#">Next</a></div>
</div>
-*/
\ No newline at end of file
+*/
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/