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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值