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

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));
			                }
			            }
			        ]
				});
			});










评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值