Ext4 重写年月控件(解决31号选择其它月份会跳月的问题)

来源:互联网 发布:淘宝男款白衬衫 编辑:程序博客网 时间:2024/05/22 02:25

Ext 文件MonthField.js,,,,,,,,,2012-6-4最终修改;

修改了年月控件也有跳月的情况,改情况为当天为xxxx-xx-31号时.选择2月会跳到三月的问题.

这个情况会在所有日期控件的中发生.是ext目前没有处理的一个问题.该解决我在我的前个文章中也写了.

现在OK了.大家请尽情的使用吧.如有其它bug请大家解决后把自己的代码放上来参考...

Ext.define('Ext.form.field.Month', {    extend: 'Ext.form.field.Date',    alias: 'widget.monthfield',    requires: ['Ext.picker.Month'],    alternateClassName: ['Ext.form.MonthField', 'Ext.form.Month'],    selectMonth: null,    createPicker: function () {        var me = this,            format = Ext.String.format;        return Ext.create('Ext.picker.Month', {            pickerField: me,            ownerCt: me.ownerCt,            renderTo: document.body,            floating: true,            hidden: true,            focusOnShow: true,            minDate: me.minValue,            maxDate: me.maxValue,            disabledDatesRE: me.disabledDatesRE,            disabledDatesText: me.disabledDatesText,            disabledDays: me.disabledDays,            disabledDaysText: me.disabledDaysText,            format: me.format,            showToday: me.showToday,            startDay: me.startDay,            minText: format(me.minText, me.formatDate(me.minValue)),            maxText: format(me.maxText, me.formatDate(me.maxValue)),            listeners: {                select: { scope: me, fn: me.onSelect },                monthdblclick: { scope: me, fn: me.onOKClick },                yeardblclick: { scope: me, fn: me.onOKClick },                OkClick: { scope: me, fn: me.onOKClick },                CancelClick: { scope: me, fn: me.onCancelClick }            },            keyNavConfig: {                esc: function () {                    me.collapse();                }            }        });    },    onCancelClick: function () {        var me = this;        me.selectMonth = null;        me.collapse();    },    onOKClick: function () {        var me = this;        if (me.selectMonth) {            me.setValue(me.selectMonth);            me.fireEvent('select', me, me.selectMonth);        }        me.collapse();    },    onSelect: function (m, d) {        var me = this;        me.selectMonth = new Date((d[0] + 1) + '/1/' + d[1]);    },//这个很重要.否则选择月份的时候会跳到下一个月    safeParse : function(value, format) {     var me = this,         utilDate = Ext.Date,         result = null,         strict = me.useStrict,         parsedDate;     if (utilDate.formatContainsHourInfo(format)) {         result = utilDate.parse(value, format, strict);     } else {         if (format == 'Y-m') {         value = value + '-01';         format = 'Y-m-d';         }                  parsedDate = utilDate.parse(value + ' ' + me.initTime, format + ' ' + me.initTimeFormat, strict);         if (parsedDate) {             result = utilDate.clearTime(parsedDate);         }     }     return result; }    });


Html 文件引用

Ext.onReady(function () {Ext.create('Ext.form.Panel', {    renderTo: Ext.getBody(),    width: 300,    bodyPadding: 10,    title: 'Dates',    items: [{                xtype: 'monthfield',                submitFormat: 'Y-m-01',                name: 'month',                fieldLabel: 'month',                format: 'Y-m',                listeners: {        select: {            fn: function(field, value, eOpts){             //field.的日期还是以当前日期最高值出现            alert(Ext.util.Format.date(field.getValue(),"Y-m-d") + " ****** " + Ext.util.Format.date(value,"Y-m-d"));            }        }  }            },            {                xtype: 'datefield',                submitFormat: 'Y-m-d',                name: 'date',                fieldLabel: 'date'            }],    buttons: [            {                text: 'send',                handler: function () {                    Ext.Msg.alert('Form will submit:', this.up('form').getForm().getValues(true));                }            }        ]});});










原创粉丝点击