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.
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.
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" />
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.