读书人

解决Ext.form.TextField的maxLength s

发布时间: 2012-11-23 00:03:43 作者: rapoo

解决Ext.form.TextField的maxLength siz属性问题

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

读书人网 >Web前端

热点推荐