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的引用之后就可以了
转帖: http://www.iteye.com/topic/232831
本文介绍了一种解决ExtJS中TextField组件maxLength属性不起作用的方法。通过对TextField原型进行重定义,确保了设置的最大长度能够被正确应用。
1万+

被折叠的 条评论
为什么被折叠?



