Ext .form.TextField 的 maxLength/size 处理的并不是很好
设置了maxLength后虽然有提示,但是还是可以任意输入,国外extjs论坛看到有人的帖子,通过prototype重定义这两个属性,试了一下,很有效
Ext.form.TextField.prototype.size=3; //要限制的长度
Ext.form.TextField.prototype.initValue = function()
{
if(this.value !== undefined){
this.setValue(this.value);
}else if(this.el.dom.value.length > 0){
this.setValue(this.el.dom.value);
}
this.el.dom.size = this.size;
if (!isNaN(this.maxLength) && (this.maxLength *1) > 0 && (this.maxLength != Number.MAX_VALUE)) {
this.el.dom.maxLength = this.maxLength *1;
}
};
上面的js放在ext -all.js的引用之后就可以
var address_1 = new Ext.form.NumberField({
name:'address1',
allowBlank:false,
allowDecimals:false,//屏蔽小数
allowNegative:false,//屏蔽负数
maxValue:255,
minValue:0,
maxLength:3,
selectOnFocus:true,
width:40
});