PDA

View Full Version : Textfield maxlength vs stripCharsRe when pasting



Spenna
18 Oct 2013, 2:23 AM
Hi all.

I'm trying to configure a textfield to only accept numbers (phone numbers with max length 8), but have a problem when pasting a number with spaces.
I.e pasting 999 99 999 should result in 99999999 in the field, but due to the enforceMaxLength it seems length is chopped before stripCharsRe is applied, so the result is 999999
Anyone have some input?

This is my current configuration:


{
xtype: 'textfield',
fieldLabel: 'Recipient',
emptyText: 'Number',
name: 'number',
maxLength: 8,
enforceMaxLength: true,
invalidText: 'Not a valid cellphone number',
regex: /^[4|9][0-9]{7}$/, // norwegian cellphone numbers
maskRe: /[0-9]/, // only accept numbers
stripCharsRe: /(\s+)/g, // strip spaces
allowBlank: false
}

evant
18 Oct 2013, 3:04 PM
There's not really much way around it, enforceMaxLength uses the browser maxlength on the input, so if you've configured it that way, that's just how it's going to end up. You'd have to disable that config to get the behaviour you're looking for.

Spenna
21 Oct 2013, 5:47 AM
Well, disabling that config does not do what i'm after, because i still want to limit input to 8 digits. I want to clean the input string for spaces before applying to field (stripCharsRe). I suppose the only approach is to listen to onPaste on the underlying dom element.