博文

目前显示的是 二月, 2013的博文

改进EXTJS的maxlength设置

在写Extjs3的时候,发现textfield输入框的maxlength设置之后不能限制输入的长度,只能在输入超出maxlength之后给出错误提示。 Google之后,发现可以把下段代码放入程序,一起加载就可以解决这个问题。 // To fix the maxlength property // if the textfield sets {maxlength} property, it cannot be inputted more than {maxlength} characters. // before fixing, the textfield can be inputted any amount of characters. When it lose focus, the validation messages will show. Ext.form.TextField.prototype.size = 255; 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; } };