Ext.apply(Ext.form.VTypes, {
sField : function(val, field) {
var f = field.getValue();
var sf = field.tScope[field.smallerField].getValue();
if (!Ext.isEmpty(f) && !Ext.isEmpty(sf) && Number(sf) >Number(f)) {
return false;
} else {
return true;
}
},
sFieldText : '結束日期不能小於開始日期',
smallerEqField : function(val, field){
var f = field.getValue();
var sf = field.tScope[field.smallerEqField].getValue();
if (!Ext.isEmpty(f) && !Ext.isEmpty(sf) && Number(sf) >= Number(f)) {
return false;
} else {
return true;
}
},
smallerEqFieldText : '結束日期不能小於或等於開始日期'
});
以上是這個類的擴展,使用的方式如下:
其中有一篇帖子講解如何重寫VTypes,點擊Ext.form.VTypes
{
xtype : "container",
layout : "form",
colspan : 1,
items : {
xtype : 'sysDateField',
fieldLabel : '開始日期',
hiddenName : 'bdate',
value : App.defaultValue.date,//設置的默認值,是系統當前的時間
allowBlank : false
}
}, {
xtype : "container",
layout : "form",
colspan : 1,
items : {
xtype : 'sysDateField', //重寫了datefield,無關緊要
fieldLabel : '結束日期',
hiddenName : 'edate',
vtype : 'sField',
smallerField : 'bdate',
tScope : this,
value : '20991231', //日期格式,處理時可以作爲整形,方便處理。
allowBlank : false
}
}