Ext.form.TextField 的 maxLength/size 处理的并不是很好
设置了maxLength后还是可以任意输入,国外extjs论坛看到有人的帖子,通过prototype重定义这两个属性,试了一下,很有效
// Textfield ignores size attribute of text..
Ext.form.TextField.prototype.size = 20;
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的引用之后就可以了
设置了maxLength后还是可以任意输入,国外extjs论坛看到有人的帖子,通过prototype重定义这两个属性,试了一下,很有效
// Textfield ignores size attribute of text..
Ext.form.TextField.prototype.size = 20;
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的引用之后就可以了