zoukankan      html  css  js  c++  java
  • 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);
    }

     
  • 相关阅读:
    HDU 5444 Elven Postman (2015 ACM/ICPC Asia Regional Changchun Online)
    POJ 1577 Falling Leaves 二叉搜索树
    HDU 3791 二叉搜索树
    Problem: Godfather 树的重心
    Problem: [Poi0202]Travelling Salesman 最近公共祖先
    Problem: 最优连通子集
    Problem: 扫雪系列II
    Problem: 扫雪系列I
    Problem: [Ural1039]没有上司的晚会
    Problem: 八中教室的灯
  • 原文地址:https://www.cnblogs.com/huige-you/p/4698650.html
Copyright © 2011-2022 走看看