caclark
06-30-2008, 02:17 PM
I have a login window for my app. I want the cursor to Do The Right Thing and start in the user Id edittext. Seems pretty simple, but it doesn't work. Here's a sample app. It's not the code that I'm running, but a simplified test case.
When the canvas init's, I set focus to the userId form field. The cursor doesn't show up and you don't get typed text in the userId field.
Button 1 sets focus to the userId form field just as the oninit handler did. However, it works.
Button 2 prints some useful info the debug console, which oddly enough, is the same if you press it immediately after the app loads and after you press Button 1.
Any suggestion on how to make this work?
Thanks,
Cary
<?xml version="1.0" standalone="no"?>
<!DOCTYPE canvas SYSTEM "http://www.laszlosystems.com/lps/tools/lzx.dtd">
<canvas>
<handler name="oninit">
<![CDATA[
Debug.write( "\ntestFocus.lzx::canvas::oninit: inited...width:", this.width, " height:", this.height ) ;
var formField = this.searchSubviews( "name", "userId" ) ;
Debug.write( "testFocus.lzx::canvas::oninit: setting focus to:", formField.name ) ;
LzFocus.setFocus( formField );
]]>
</handler>
<vbox>
<hbox name="namePart" x="15" fontsize="12" >
<text fontsize="12" >User Id:</text>
<edittext height="20" width="130" x="70"
name="userId" >
<handler name="onfocus">
Debug.write( "\n" + this.name + "::onfocus\n\n" ) ;
</handler>
</edittext>
</hbox>
<hbox name="pwdPart" fontsize="12" >
<text fontsize="12">Password:</text>
<edittext height="20" x="70" width="130"
name="password" password="true" >
<handler name="onfocus">
Debug.write( "\n" + this.name + "::onfocus\n\n" ) ;
</handler>
</edittext>
</hbox>
<hbox>
<button name="button1" >Button 1
<handler name="onclick">
var formField = parent.parent.namePart.userId ;
Debug.write( "setting focus to:", formField ) ;
LzFocus.setFocus(formField) ;
</handler>
</button>
<button name="button2" >Button 2
<handler name="onclick">
Debug.write( "focused:", LzFocus.getFocus(), " last:", LzFocus.lastfocus, " prev:", LzFocus.getPrev() ) ;
</handler>
</button>
</hbox>
</vbox>
</canvas>
When the canvas init's, I set focus to the userId form field. The cursor doesn't show up and you don't get typed text in the userId field.
Button 1 sets focus to the userId form field just as the oninit handler did. However, it works.
Button 2 prints some useful info the debug console, which oddly enough, is the same if you press it immediately after the app loads and after you press Button 1.
Any suggestion on how to make this work?
Thanks,
Cary
<?xml version="1.0" standalone="no"?>
<!DOCTYPE canvas SYSTEM "http://www.laszlosystems.com/lps/tools/lzx.dtd">
<canvas>
<handler name="oninit">
<![CDATA[
Debug.write( "\ntestFocus.lzx::canvas::oninit: inited...width:", this.width, " height:", this.height ) ;
var formField = this.searchSubviews( "name", "userId" ) ;
Debug.write( "testFocus.lzx::canvas::oninit: setting focus to:", formField.name ) ;
LzFocus.setFocus( formField );
]]>
</handler>
<vbox>
<hbox name="namePart" x="15" fontsize="12" >
<text fontsize="12" >User Id:</text>
<edittext height="20" width="130" x="70"
name="userId" >
<handler name="onfocus">
Debug.write( "\n" + this.name + "::onfocus\n\n" ) ;
</handler>
</edittext>
</hbox>
<hbox name="pwdPart" fontsize="12" >
<text fontsize="12">Password:</text>
<edittext height="20" x="70" width="130"
name="password" password="true" >
<handler name="onfocus">
Debug.write( "\n" + this.name + "::onfocus\n\n" ) ;
</handler>
</edittext>
</hbox>
<hbox>
<button name="button1" >Button 1
<handler name="onclick">
var formField = parent.parent.namePart.userId ;
Debug.write( "setting focus to:", formField ) ;
LzFocus.setFocus(formField) ;
</handler>
</button>
<button name="button2" >Button 2
<handler name="onclick">
Debug.write( "focused:", LzFocus.getFocus(), " last:", LzFocus.lastfocus, " prev:", LzFocus.getPrev() ) ;
</handler>
</button>
</hbox>
</vbox>
</canvas>