Flex - Set focus on one component until user enters some value
I am trying to write the code for making a text input control in flex.
As the user enters the value in text input control and then if he removes the typed characters to make the text input blank, then I print error messag开发者_如何学Ce via StringValidator.But I want the focus to be set on that text input only until the user enters anything. How can I achieve that ?
Thanks
Like David said, I would just check if the string is empty using the focusOut event. Of course, you still have to add the StringValidator logic to the code..
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function focusOutHandler(event:FocusEvent):void
{
if (event.target.text == '')
event.target.setFocus();
}
]]>
</fx:Script>
<s:TextInput id="myTextInput" focusOut="focusOutHandler(event)"/>
</s:WindowedApplication>
Try listening for a FocusEvent.FOCUS_OUT
on the text field, then re-focus it if it's blank.
精彩评论