From 9bad31f5624bb44918873ee6ede5b0f4d559ab30 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Mon, 16 Mar 2009 02:27:08 +0000 Subject: [PATCH] formslib dates: MDL-16592 Fix problem when trying to select a time when the calendar is not visible. --- lib/javascript-static.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/javascript-static.js b/lib/javascript-static.js index e197e2114d..8b60764308 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -349,7 +349,7 @@ function init_date_selectors(firstdayofweek) { } /** - * Constructor for a JavaScritp object that connects to a fdate_time_selector + * Constructor for a JavaScript object that connects to a fdate_time_selector * or a fdate_selector in a Moodle form, and shows a popup calendar whenever * that element has keyboard focus. * @param el the fieldset class="fdate_time_selector" or "fdate_selector". @@ -383,21 +383,22 @@ function date_selector_calendar(el, firstdayofweek) { this.fieldset = el; var controls = el.getElementsByTagName('select'); for (var i = 0; i < controls.length; i++) { - YAHOO.util.Event.addFocusListener(controls[i], this.focus_event, this); - YAHOO.util.Event.addBlurListener(controls[i], this.blur_event, this); if (/\[year\]$/.test(controls[i].name)) { this.yearselect = controls[i]; - } - if (/\[month\]$/.test(controls[i].name)) { + } else if (/\[month\]$/.test(controls[i].name)) { this.monthselect = controls[i]; - } - if (/\[day\]$/.test(controls[i].name)) { + } else if (/\[day\]$/.test(controls[i].name)) { this.dayselect = controls[i]; + } else { + YAHOO.util.Event.addFocusListener(controls[i], this.cancel_any_timeout, this); + YAHOO.util.Event.addBlurListener(controls[i], this.blur_event, this); } } if (!(this.yearselect && this.monthselect && this.dayselect)) { throw 'Failed to initialise calendar.'; } + YAHOO.util.Event.addFocusListener([this.yearselect, this.monthselect, this.dayselect], this.focus_event, this); + YAHOO.util.Event.addBlurListener([this.yearselect, this.monthselect, this.dayselect], this.blur_event, this); this.enablecheckbox = el.getElementsByTagName('input')[0]; if (this.enablecheckbox) { @@ -446,7 +447,7 @@ date_selector_calendar.prototype.focus_event = function(e, me) { } date_selector_calendar.prototype.blur_event = function(e, me) { - date_selector_calendar.hidetimeout = setTimeout(function() {me.release_calendar()}, 200); + date_selector_calendar.hidetimeout = setTimeout(function() {me.release_calendar();}, 200); } date_selector_calendar.prototype.handle_select_change = function(e, me) { -- 2.39.5