fixed: DateTime Form Control Bug

This commit is contained in:
Yung Han Khoe 2008-08-03 14:46:55 +00:00
parent fd62170df6
commit eca4ccc998
2 changed files with 34 additions and 20 deletions

View file

@ -19,6 +19,7 @@
- fixed: EMS purge now functions correctly - fixed: EMS purge now functions correctly
- improve behavior of preload.perl for custom lib dirs not ending in lib - improve behavior of preload.perl for custom lib dirs not ending in lib
- fixed: Server side spellchecker doesn't work - fixed: Server side spellchecker doesn't work
- fixed: DateTime Form Control Bug
7.5.18 7.5.18
- fixed: Collateral Image Manager broken in Firefox 3 - fixed: Collateral Image Manager broken in Firefox 3

View file

@ -34,42 +34,55 @@ YAHOO.WebGUI.Form.DatePicker = {
}, },
handleRender: function(e) { handleRender: function(e) {
if ( this.useTime ) { if ( this.useTime ) {
this.addTimeBox();
}
},
addTimeBox: function(e) {
this.timediv = document.createElement('div'); this.timediv = document.createElement('div');
YAHOO.util.Dom.setStyle(this.timediv, 'text-align', 'center'); YAHOO.util.Dom.setStyle(this.timediv, 'text-align', 'center');
this.calendar.oDomContainer.appendChild(this.timediv); this.calendar.oDomContainer.appendChild(this.timediv);
this.timediv.appendChild(document.createTextNode('Time: ')); this.timediv.appendChild(document.createTextNode('Time: '));
this.hourEl = document.createElement('input'); this.hourEl = document.createElement('input');
this.hourEl.value = '00'; this.hourEl.value = this.hour;
this.hourEl.setAttribute('size', 2); this.hourEl.setAttribute('size', 2);
this.hourEl.setAttribute('maxlength', 2); this.hourEl.setAttribute('maxlength', 2);
this.timediv.appendChild(this.hourEl); this.timediv.appendChild(this.hourEl);
this.timediv.appendChild(document.createTextNode(' : ')); this.timediv.appendChild(document.createTextNode(' : '));
this.minuteEl = document.createElement('input'); this.minuteEl = document.createElement('input');
this.minuteEl.value = '00'; this.minuteEl.value = this.min;
this.minuteEl.setAttribute('size', 2); this.minuteEl.setAttribute('size', 2);
this.minuteEl.setAttribute('maxlength', 2); this.minuteEl.setAttribute('maxlength', 2);
this.timediv.appendChild(this.minuteEl); this.timediv.appendChild(this.minuteEl);
this.secEl = document.createElement('input'); this.secEl = document.createElement('input');
this.secEl.value = '00'; this.secEl.value = this.sec;
this.secEl.setAttribute('size', 2); this.secEl.setAttribute('size', 2);
this.secEl.setAttribute('maxlength', 2); this.secEl.setAttribute('maxlength', 2);
YAHOO.util.Dom.setStyle(this.secEl, 'display', 'none'); YAHOO.util.Dom.setStyle(this.secEl, 'display', 'none');
this.timediv.appendChild(this.secEl); this.timediv.appendChild(this.secEl);
this.calendar.oDomContainer.appendChild(this.timediv); this.calendar.oDomContainer.appendChild(this.timediv);
this.timeBoxAdded = true;
YAHOO.util.Event.on(this.hourEl, 'change', this.handleTimebox, [this.hourEl, 'hour'], this); YAHOO.util.Event.on(this.hourEl, 'change', this.handleTimebox, [this.hourEl, 'hour'], this);
YAHOO.util.Event.on(this.minuteEl, 'change', this.handleTimebox, [this.minuteEl, 'minute'], this); YAHOO.util.Event.on(this.minuteEl, 'change', this.handleTimebox, [this.minuteEl, 'minute'], this);
}
}, },
handleTimebox: function(e, obj) { handleTimebox: function(e, obj) {
var input = obj[0]; var input = obj[0];
var type = obj[1]; var type = obj[1];
var val = parseInt(input.value); var val = parseInt(input.value);
if (type == 'hour'){
this.hour = val;
}
if (type == 'minute'){
this.min = val;
}
if (!val) if (!val)
val = 0; val = 0;
val = val % (type == 'hour' ? 24 : 60); val = val % (type == 'hour' ? 24 : 60);
input.value = (val < 10 ? '0' : '') + val; input.value = (val < 10 ? '0' : '') + val;
}, },
handleBeforeShow: function(e) { handleBeforeShow: function(e) {
if ( this.useTime && !this.timeBoxAdded) {
this.addTimeBox();
}
YAHOO.util.Event.on(this.inputBox, 'change', this.handleChange, this, true); YAHOO.util.Event.on(this.inputBox, 'change', this.handleChange, this, true);
this.handleChange(); this.handleChange();
}, },
@ -110,24 +123,27 @@ YAHOO.WebGUI.Form.DatePicker = {
this.codeSelect = true; this.codeSelect = true;
var date; var date;
var res; var res;
var hour, min, sec;
if(res = this.inputBox.value.match(/(\d+)-(\d+)-(\d+)(?: (\d+):(\d+):(\d+))?/)) { if(res = this.inputBox.value.match(/(\d+)-(\d+)-(\d+)(?: (\d+):(\d+):(\d+))?/)) {
date = res[1] + '-' + res[2] + '-' + res[3]; date = res[1] + '-' + res[2] + '-' + res[3];
if (res[4]) { if (res[4]) {
hour = (res[4] < 10 ? '0' : '') + (1 * res[4]); if (!this.hour){
min = (res[5] < 10 ? '0' : '') + (1 * res[5]); this.hour = (res[4] < 10 ? '0' : '') + (1 * res[4]);
sec = (res[6] < 10 ? '0' : '') + (1 * res[6]); }
if (!this.min){
this.min = (res[5] < 10 ? '0' : '') + (1 * res[5]);
}
this.sec = (res[6] < 10 ? '0' : '') + (1 * res[6]);
} }
} }
if (!hour) if (!this.hour)
hour = '00'; this.hour = '00';
if (!min) if (!this.min)
min = '00'; this.min = '00';
if (!sec) if (!this.sec)
sec = '00'; this.sec = '00';
this.hourEl.value = hour; this.hourEl.value = this.hour;
this.minuteEl.value = min; this.minuteEl.value = this.min;
this.secEl.value = sec; this.secEl.value = this.sec;
this.calendar.select(date); this.calendar.select(date);
var selectedDates = this.calendar.getSelectedDates(); var selectedDates = this.calendar.getSelectedDates();
if (selectedDates.length > 0) { if (selectedDates.length > 0) {
@ -135,9 +151,6 @@ YAHOO.WebGUI.Form.DatePicker = {
this.calendar.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "-" + firstDate.getFullYear()); this.calendar.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "-" + firstDate.getFullYear());
this.calendar.render(); this.calendar.render();
} }
this.hourEl.value = hour;
this.minuteEl.value = min;
this.secEl.value = sec;
this.codeSelect = false; this.codeSelect = false;
} }
} }