2

I wish to remove specific characters inside Spark TextInput while user typing on it, without this causing any distrbance like licking with mouse after the last character or alike.

  • Any suggestions is appreciated.
4

2 回答 2

1

Have you tried restrict property of the TextInput? I don't know what are your specific characters, but commonly there are 2 cases of restriction. Restrict to a set of characters:

<s:TextInput restrict="A-Za-z" />

Allow all characters except some special characters:

<s:TextInput restrict="^0-9" />

To deal with unicode characters, use \u:

<s:TextInput restrict="\u0239" />
于 2011-06-15T10:16:35.723 回答
1

You can create your own custom TextInput component and override the keyDownHandler() or you can add a event listener on the TextInput, like this:

<s:TextInput keyDown="{ textInputKeyDownHandler(event) }"/>

and then on the event handler:

private function textInputKeyDownHandler(event:KeyboardEvent):void {
    // Make your validations and if necessary, use the following command 
    // to prevent the character from being added to the TextInput
    event.preventDefault();
}

This way the character will never be added to the TextInput, which means the text property and the cursor position will not change.

Note: Use the event.charCode and event.keyCode to make the necessary validations.

于 2011-06-15T13:00:48.547 回答