View Full Version : Remove leading and trailing blanks in all fields by default

14 Oct 2009, 5:52 AM
I'd like to have all my text fields ignore leading and trailing white space.

From this thread I learned that you can configure that by using a regular expression in a text
field's config option:

stripCharsRe: /(^\s+|\s+$)/gHowever I really don't want to add that property to all my fields individually nor do I want to to use a subclass of TextField everywhere.

So what is a good way to change the _default_ right at Ext.form.TextField (without changing the original source code)?

14 Oct 2009, 5:56 AM
Use Ext.override to modify the prototype of the class. Place this code immediately after your ext-all(-debug).js in a file called ext-overrides.js.

stripCharsRe: /(^\s+|\s+$)/g

14 Oct 2009, 6:28 AM
Doh, I am still thinking to much in Java: I even knew about Ext.override, but mentally only applied it to "methods", even though in JavaScript everything's just a property.

Sadly, the solution does not really work for a completely different reason: The validation kicks in even while the user is still typing, and it actually strips the spaces from the text field's content, so to type "two words" you must type very fast, else it becomes "twowords".

What I am after is to have the whitespace ignored for validation, but to only really strip them later. I am not sure what the correct definition for "later" is, though. Maybe on blur - or is there a "commit" event of some kind?

14 Oct 2009, 6:35 AM
Should get what you need by hooking onto blur and trim (http://www.extjs.com/deploy/dev/docs/?class=Ext.util.Format&member=trim)'ng the whitespace.