* @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
});
};
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) {
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');
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;
fillMonths: function()
{
- var i = 0
+ var i = 0;
var months = this.picker().select('>.datepicker-months td', true).first();
months.dom.innerHTML = '';
tag: 'span',
cls: 'month',
html: Roo.bootstrap.DateField.dates[this.language].monthsShort[i++]
- }
+ };
months.createChild(month);
}
tag: 'td',
cls: 'day ' + clsName,
html: prevMonth.getDate()
- })
+ });
prevMonth.setDate(prevMonth.getDate()+1);
}
tag: 'span',
cls: 'year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : ''),
html: year
- })
+ });
year += 1;
}
place: function()
{
- if(this.isInline) return;
+ if(this.isInline) {
+ return;
+ }
this.picker().removeClass(['bottom', 'top']);
},
formatDate : function(date, fmt)
- {
- Roo.log(date.dateFormat);
+ {
return (!date || !(date instanceof Date)) ?
date : date.dateFormat(fmt || this.format);
},
hide : function()
{
- if(this.isInline) return;
+ if(this.isInline) {
+ return;
+ }
this.picker().hide();
this.viewMode = this.startViewMode;
this.showMode();
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()
fireKey: function(e)
{
if (!this.picker().isVisible()){
- if (e.keyCode == 27) // allow escape to hide and re-show picker
+ if (e.keyCode == 27) { // allow escape to hide and re-show picker
this.show();
+ }
return;
}
break;
case 37: // left
case 39: // right
- if (!this.keyboardNavigation) break;
+ if (!this.keyboardNavigation) {
+ break;
+ }
dir = e.keyCode == 37 ? -1 : 1;
if (e.ctrlKey){
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);
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(),
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<mag; i++)
+ for (var i=0; i<mag; i++) {
// ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
new_date = this.moveMonth(new_date, dir);
+ }
// ...then reset the day, keeping it in the new month
new_month = new_date.getUTCMonth();
new_date.setUTCDate(day);
remove: function()
{
this.picker().remove();
+ },
+
+ validateValue : function(value)
+ {
+ if(this.getVisibilityEl().hasClass('hidden')){
+ return true;
+ }
+
+ if(value.length < 1) {
+ if(this.allowBlank){
+ return true;
+ }
+ return false;
+ }
+
+ if(value.length < this.minLength){
+ return false;
+ }
+ if(value.length > 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;
+ },
+
+ setVisible : function(visible)
+ {
+ if(!this.getEl()){
+ return;
+ }
+
+ this.getEl().removeClass('hidden');
+
+ if(visible){
+ return;
+ }
+
+ this.getEl().addClass('hidden');
}
});
template : {
tag: 'div',
- cls: 'datepicker dropdown-menu',
+ cls: 'datepicker dropdown-menu roo-dynamic',
cn: [
{
tag: 'div',