View Full Version : NumberField Bug w/MaxLength

5 Jun 2007, 5:42 AM
Ext: 1.0.1 and 1.1.b1

I have the following Field Definition:

memberNo = new Ext.form.NumberField({
fieldLabel: 'Member No',
id: 'memberidno',
name: 'memberidno',
value: ''

Yet the input allows you to type in more than 10 digits. The warning icon does pop up to the right of the input if the user enters more than 10 digits... But I was would like to restrict the user from typing in more than 10 digits similar to the following html code:

<input type=text name=memberidno value='' size=20 maxlength=10 >

Does anyone know how to restrict the entry of 10 or less digits using EXT?

Thanks in Advance!!!

5 Jun 2007, 6:24 AM
I don't know if there is a better "Ext way" of doing this (it seems that there should be an explicit config option that does what you need), but this could be a quick solution: get the underlying HTML input element, and set its HTML maxlength attribute:

memberNo.getEl().dom.setAttribute("maxlength", "10");

5 Jun 2007, 7:10 AM
You are right, the maxLength config option in TextField ( which NumberField subclasses) isn't overwriting the default value of Number.MAX_VALUE....

I tried using your suggestion right after I instantiate the object...
but I kept getting a javascript error: "El() has no properties"...

I had to put the code right after the form.render() line and all is working now...

Thanks for the Assistance!!