PDA

View Full Version : [Solved]Textfields for specific Character



giehl
12 Jun 2011, 7:40 AM
How to setting textfields that can only be edited by a specific character?
(ex. number)

Solved: Iam using this code for textfield

maskRe: /^([0-9])$/

Thanks for "skirtle";)

skirtle
12 Jun 2011, 8:43 AM
This is covered in the introduction in the docs:

http://dev.sencha.com/deploy/ext-3.4.0/docs/?class=Ext.form.TextField

maskRe and stripCharsRe.

If you're specifically interested in numbers then see:

http://dev.sencha.com/deploy/ext-3.4.0/docs/?class=Ext.form.NumberField

If you click the 'Hide Inherited Members' button (blue up arrow with red minus, top-right toolbar) it'll show you specific settings for number configuration.

giehl
14 Jun 2011, 3:12 AM
I was used numberfield before, but when I entry data like this "196411051990031003" it goes "196411051990031000".
003 to 000, any advice? And how to make textfield just for number character?



Thanks

skirtle
16 Jun 2011, 10:40 AM
You cannot represent such large integers precisely using numbers in JavaScript, as you've observed you get rounding. Do you really need such big numbers? If you do then you'll need to keep them as strings.

As for implementing your own number-only TextField, I suggest you have a read of the source code for NumberField:

http://dev.sencha.com/deploy/ext-3.4.0/docs/source/NumberField.html#cfg-Ext.form.NumberField-baseChars

The initEvents() method is particularly relevant but all it does is use the config options I mentioned previously.

giehl
17 Jun 2011, 10:09 PM
But, how I can implement textfield for number with baseChars?

skirtle
18 Jun 2011, 9:27 AM
Just use a maskRe of /\d/ and a stripCharsRe of /^\D*0+(?=.*\d)|\D/g.

giehl
18 Jun 2011, 6:23 PM
Just use a maskRe of /\d/ and a stripCharsRe of /^\D*0+(?=.*\d)|\D/g.

Hows that work? When I implemented that, just char "d" that I can typed...

skirtle
18 Jun 2011, 6:41 PM
\d matches a numeric digit whereas just d would match the letter d, I can only assume you've typed it in wrong. Regular expressions are bread-and-butter programming, please read a tutorial so that you can fix trivial mistakes like this by yourself.

Try copy and paste to make sure you type it in right:


new Ext.form.TextField({
maskRe: /\d/,
renderTo: Ext.getBody(),
stripCharsRe: /^\D*0+(?=.*\d)|\D/g
});

giehl
18 Jun 2011, 6:45 PM
I was followed ur advice, but it same as before.

skirtle
18 Jun 2011, 7:14 PM
The only thing I can think of is that whatever browser you are using doesn't support \d and \D. I can't find any mention of this online, nor do any of the browsers I have exhibit this problem, including IE6.

On the off chance it is that, you could use the character classes of [0-9] and [^0-9] to replace them. I repeat, please read a tutorial.

giehl
18 Jun 2011, 8:14 PM
I'm very sorry, skirtle.... But I cant understand that tutorial say.... Sorry. Thank you very much.... :D