I've got it working, just made a few changes to your code:
* I got a handle on the focus manager before setting focus
* defaultButton as attribute of Form, not panel.
Otherwise, all is well.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
creationComplete="checkLoginFormForSelection();">
<mx:Script><![CDATA[
private function checkLoginFormForSelection() : Void{
var fm = getFocusManager();
if (email.length == 0) {
fm.setFocus(email);
Selection.setSelection(1,1)
return;
}
if (password.length == 0) {
fm.setFocus(password);
Selection.setSelection(1,1)
return;
}
}
]]></mx:Script>
<mx:Panel title="Login Form Focus" >
<mx:Form defaultButton="login">
<mx:FormItem label="Email">
<mx:TextInput id="email" text="[EMAIL PROTECTED]"/>
</mx:FormItem>
<mx:FormItem label="Password">
<mx:TextInput id="password" text=""/>
</mx:FormItem>
</mx:Form>
<mx:Button click="mx.controls.Alert.show('You just logged in');"
label="Login" id="login"/>
</mx:Panel>
</mx:Application>
At 12:04 PM 7/28/2005, Allen Manning wrote:
>Hello Flexcoders,
>
>I'm working on a simple login form and attempting to accomplish the following:
>
>+ Assign a default button to login so after page loads and you hit enter
>the form submits, no need to click in to the page.
>+ Assign selection to the first of the two text fields that have no text,
>otherwise focus should be on the button.
>
>I have made a few attempts but I have not been able to get it all working,
>only some of the functionality here and there.
>
>Thanks for any help,
>Allen
><http://www.prismix.com/>www.prismix.com/
>
><?xml version="1.0" encoding="utf-8"?>
><mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml"
> initialize="checkLoginFormForSelection();">
> <mx:Script><![CDATA[
> private function checkLoginFormForSelection() : Void
> {
>
> if (email.text.length == 0) {
>
> email.setFocus(email);
> Selection.setSelection(1,1)
> return;
>
> }
>
> if (password.text.length == 0) {
>
> password.setFocus(password);
> Selection.setSelection(1,1)
> return;
>
> }
>
> }
> ]]></mx:Script>
> <mx:Panel title="Login Form Focus" defaultButton="login">
> <mx:Form>
> <mx:FormItem label="Email">
> <mx:TextInput id="email" text="[EMAIL PROTECTED]"/>
> </mx:FormItem>
> <mx:FormItem label="Password">
> <mx:TextInput id="password" text=""/>
> </mx:FormItem>
> </mx:Form>
> <mx:Button click="mx.controls.Alert.show('You just logged in');"
> label="Login" id="login"/>
> </mx:Panel>
></mx:Application>
>
>
>
>
>--
>Flexcoders Mailing List
>FAQ:
><http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt>http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
>Search Archives:
><http://www.mail-archive.com/flexcoders%40yahoogroups.com>http://www.mail-archive.com/flexcoders%40yahoogroups.com
>
>
>
>
>
>----------
>YAHOO! GROUPS LINKS
>
> * Visit your group
> "<http://groups.yahoo.com/group/flexcoders>flexcoders" on the web.
> *
> * To unsubscribe from this group, send an email to:
> *
> <mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]
>
> *
> * Your use of Yahoo! Groups is subject to the
> <http://docs.yahoo.com/info/terms/>Yahoo! Terms of Service.
>
>
>----------
>
>--
>Outgoing mail is certified Virus Free.
>Checked by AVG Anti-Virus (http://www.grisoft.com).
>Version: 7.0.269 / Virus Database: 267.9.5 - Release Date: 25/07/2005
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/