Extjs DateField Bug 当format为年月'Y-m',在当前月(30、31号)选择其他偶数月会乱跳的问题解决方案

    Ext.form.WMDateField = Ext.extend(Ext.form.DateField, {
        safeParse : function(value, format) {
              if (/[gGhH]/.test(format.replace(/(\.)/g, ''))) {
                return Date.parseDate(value, format);
            } else if ("Y-m" == format) {
                var parsedDate = Date.parseDate(value + '-01 ' + this.initTime, format + '-d ' + this.initTimeFormat);
                if (parsedDate) {
                    return parsedDate.clearTime();
                }
            } else if ("Ym" == format) {
                var parsedDate = Date.parseDate(value + '01 ' + this.initTime, format + 'd ' + this.initTimeFormat);
                if (parsedDate) {
                    return parsedDate.clearTime();
                }
            } else {
                var parsedDate = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat);
                if (parsedDate) {
                    return parsedDate.clearTime();
                }
            }
        }
    });

    Ext.reg('wmdatefield', Ext.form.WMDateField);

日期控件定义为下面的方法:

[{
fieldLabel:'日期',
xtype:'wmdatefield',
format:'Y-m'
}]

引用----http://blog.sina.com.cn/s/blog_454fbf7401011401.html

然并卵,最终解决方案是:

改成

format:'Y-m-d'  ,然后在选择日期控件中加入下面判断,也就是下个月的00天,也就是所选择的这个月的最后一天。

// 当format参数值为Y时,设置值,并激发select事件
if (this.format.indexOf('d') != -1 && this.getValue() != date) {

var result = null;
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = 00;

var Ndate = new Date(year, month, day);

if (Ndate)
{
this.setValue(Ndate.clearTime());
}
else
{
this.setValue(date);
}

this.fireEvent('select', this, this.value);
}

 
原文地址:https://www.cnblogs.com/huige-you/p/4698650.html