Ext Textfield的maxLength如果限制长度为10,可以输入超过10个的字符,只是会给你提示,不让你的表单提交,如果加上下面代码则可以让用户只能输入不超过10个字符:
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; } };
Ext.getCmp("usernameT").on("invalid",function(){ alert("invalid");//如果输入不合法时给出提示。 });