X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Roo%2Fbootstrap%2FDateField.js;h=ba18ac35df1a2cd51b50adc28d6104dad331e8f4;hb=9be6e45a0ff049e97ab69d97706b81d8a0500fb1;hp=10cd8b8317c341f75a84e714f1a2ac5d2c85b640;hpb=155a4d6d6b849bb6c61a773514f614b8d14f39d0;p=roojs1 diff --git a/Roo/bootstrap/DateField.js b/Roo/bootstrap/DateField.js index 10cd8b8317..ba18ac35df 100644 --- a/Roo/bootstrap/DateField.js +++ b/Roo/bootstrap/DateField.js @@ -51,7 +51,14 @@ Roo.bootstrap.DateField = function(config){ * @param {Roo.bootstrap.DateField} this * @param {Mixed} date The date value */ - select : true + select : true, + /** + * @event beforeselect + * Fires when before select a date. + * @param {Roo.bootstrap.DateField} this + * @param {Mixed} date The date value + */ + beforeselect : true }); }; @@ -140,7 +147,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { this.isInput = true; this.component = this.el.select('.add-on', true).first() || false; this.component = (this.component && this.component.length === 0) ? false : this.component; - this.hasInput = this.component && this.inputEL().length; + this.hasInput = this.component && this.inputEl().length; if (typeof(this.minViewMode === 'string')) { switch (this.minViewMode) { @@ -185,9 +192,9 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { if(this.singleMode){ Roo.each(this.picker().select('thead > tr > th', true).elements, function(v){ - v.setVisibilityMode(Roo.Element.DISPLAY) + v.setVisibilityMode(Roo.Element.DISPLAY); v.hide(); - }) + }); Roo.each(this.picker().select('tbody > tr > td', true).elements, function(v){ v.setStyle('width', '189px'); @@ -198,13 +205,13 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { if(!this.calendarWeeks){ v.remove(); return; - }; + } - v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today + v.dom.innerHTML = Roo.bootstrap.DateField.dates[this.language].today; v.attr('colspan', function(i, val){ return parseInt(val) + 1; }); - }) + }); this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1; @@ -220,7 +227,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { this.showMode(); if(this.isInline) { - this.show(); + this.showPopup(); } }, @@ -262,7 +269,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { fillMonths: function() { - var i = 0 + var i = 0; var months = this.picker().select('>.datepicker-months td', true).first(); months.dom.innerHTML = ''; @@ -272,7 +279,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { tag: 'span', cls: 'month', html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++] - } + }; months.createChild(month); } @@ -335,7 +342,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { this.picker().select('>.datepicker-days tbody',true).first().dom.innerHTML = ''; - while(prevMonth.valueOf() < nextMonth) { + while(prevMonth.valueOf() <= nextMonth) { var clsName = ''; if (prevMonth.getUTCDay() === this.weekStart) { @@ -394,7 +401,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { tag: 'td', cls: 'day ' + clsName, html: prevMonth.getDate() - }) + }); prevMonth.setDate(prevMonth.getDate()+1); } @@ -430,7 +437,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { tag: 'span', cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''), html: year - }) + }); year += 1; } @@ -451,7 +458,9 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { place: function() { - if(this.isInline) return; + if(this.isInline) { + return; + } this.picker().removeClass(['bottom', 'top']); @@ -501,7 +510,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { onFocus : function() { Roo.bootstrap.DateField.superclass.onFocus.call(this); - this.show(); + this.showPopup(); }, onBlur : function() @@ -512,26 +521,28 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { this.setValue(d); - this.hide(); + this.hidePopup(); }, - show : function() + showPopup : function() { this.picker().show(); this.update(); this.place(); - this.fireEvent('show', this, this.date); + this.fireEvent('showpopup', this, this.date); }, - hide : function() + hidePopup : function() { - if(this.isInline) return; + if(this.isInline) { + return; + } this.picker().hide(); this.viewMode = this.startViewMode; this.showMode(); - this.fireEvent('hide', this, this.date); + this.fireEvent('hidepopup', this, this.date); }, @@ -549,28 +560,25 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { setValue: function(v) { + if(this.fireEvent('beforeselect', this, v) !== false){ + var d = new Date(this.parseDate(v) ).clearTime(); - // v can be a string or a date.. - - - var d = new Date(this.parseDate(v) ).clearTime(); - - if(isNaN(d.getTime())){ - this.date = this.viewDate = ''; - Roo.bootstrap.DateField.superclass.setValue.call(this, ''); - return; - } - - v = this.formatDate(d); - - Roo.bootstrap.DateField.superclass.setValue.call(this, v); - - this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000); - - this.update(); + if(isNaN(d.getTime())){ + this.date = this.viewDate = ''; + Roo.bootstrap.DateField.superclass.setValue.call(this, ''); + return; + } - this.fireEvent('select', this, this.date); - + v = this.formatDate(d); + + Roo.bootstrap.DateField.superclass.setValue.call(this, v); + + this.date = new Date(d.getTime() - d.getTimezoneOffset()*60000); + + this.update(); + + this.fireEvent('select', this, this.date); + } }, getValue: function() @@ -581,8 +589,9 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { fireKey: function(e) { if (!this.picker().isVisible()){ - if (e.keyCode == 27) // allow escape to hide and re-show picker - this.show(); + if (e.keyCode == 27) { // allow escape to hide and re-show picker + this.showPopup(); + } return; } @@ -592,12 +601,14 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { switch(e.keyCode){ case 27: // escape - this.hide(); + this.hidePopup(); e.preventDefault(); break; case 37: // left case 39: // right - if (!this.keyboardNavigation) break; + if (!this.keyboardNavigation) { + break; + } dir = e.keyCode == 37 ? -1 : 1; if (e.ctrlKey){ @@ -623,7 +634,9 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { break; case 38: // up case 40: // down - if (!this.keyboardNavigation) break; + if (!this.keyboardNavigation) { + break; + } dir = e.keyCode == 38 ? -1 : 1; if (e.ctrlKey){ newDate = this.moveYear(this.date, dir); @@ -648,19 +661,19 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { break; case 13: // enter this.setValue(this.formatDate(this.date)); - this.hide(); + this.hidePopup(); e.preventDefault(); break; case 9: // tab this.setValue(this.formatDate(this.date)); - this.hide(); + this.hidePopup(); break; case 16: // shift case 17: // ctrl case 18: // alt break; default : - this.hide(); + this.hidePopup(); } }, @@ -708,13 +721,16 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { // this.fill() this.setValue(this.formatDate(this.date)); - this.hide(); + this.hidePopup(); break; } break; case 'span': if (className.indexOf('disabled') < 0) { - this.viewDate.setUTCDate(1); + if (!this.viewDate) { + this.viewDate = new Date(); + } + this.viewDate.setUTCDate(1); if (className.indexOf('month') > -1) { this.viewDate.setUTCMonth(Roo.bootstrap.DateField.dates[this.language].monthsShort.indexOf(html)); } else { @@ -725,7 +741,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { if(this.singleMode){ this.setValue(this.formatDate(this.viewDate)); - this.hide(); + this.hidePopup(); return; } @@ -738,8 +754,8 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { //Roo.log(className); if (className.indexOf('day') > -1 && className.indexOf('disabled') < 0 ){ var day = parseInt(html, 10) || 1; - var year = this.viewDate.getUTCFullYear(), - month = this.viewDate.getUTCMonth(); + var year = (this.viewDate || new Date()).getUTCFullYear(), + month = (this.viewDate || new Date()).getUTCMonth(); if (className.indexOf('old') > -1) { if(month === 0 ){ @@ -762,7 +778,7 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { // this.fill(); //Roo.log(this.formatDate(this.date)); this.setValue(this.formatDate(this.date)); - this.hide(); + this.hidePopup(); } break; } @@ -850,7 +866,9 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { moveMonth: function(date, dir) { - if (!dir) return date; + if (!dir) { + return date; + } var new_date = new Date(date.valueOf()), day = new_date.getUTCDate(), month = new_date.getUTCMonth(), @@ -872,13 +890,15 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input, { new_month = month + dir; new_date.setUTCMonth(new_month); // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11 - if (new_month < 0 || new_month > 11) + if (new_month < 0 || new_month > 11) { new_month = (new_month + 12) % 12; + } } else { // For magnitudes >1, move one month at a time... - for (var i=0; i this.maxLength){ + return false; + } + if(this.vtype){ + var vt = Roo.form.VTypes; + if(!vt[this.vtype](value, this)){ + return false; + } + } + if(typeof this.validator == "function"){ + var msg = this.validator(value); + if(msg !== true){ + return false; + } + } + + if(this.regex && !this.regex.test(value)){ + return false; + } + + if(typeof(this.parseDate(value)) == 'undefined'){ + return false; + } + + if (this.endDate !== Infinity && this.parseDate(value).getTime() > this.endDate.getTime()) { + return false; + } + + if (this.startDate !== -Infinity && this.parseDate(value).getTime() < this.startDate.getTime()) { + return false; + } + + + return true; + }, + + reset : function() + { + this.date = this.viewDate = ''; + + Roo.bootstrap.DateField.superclass.setValue.call(this, ''); } }); @@ -1007,7 +1086,7 @@ Roo.apply(Roo.bootstrap.DateField, { template : { tag: 'div', - cls: 'datepicker dropdown-menu roo-dynamic', + cls: 'datepicker dropdown-menu roo-dynamic shadow', cn: [ { tag: 'div',