Setting focus on a specific widget when app first opens

4191
5
Jump to solution
04-10-2012 06:08 AM
KeithPalmer
New Contributor
I consider what I want to do mandatory UI functionality, but from the few posts I seen on the forums, I don't think it can be done in the current 2.5 viewer. 

Background - I am developing a Restaurant Inspection results website.  Since it will be widely used by the public, I want it to be easy and simple to use, so no extra mouse clicks necessary if possible.

Question - Is there a way to set the focus to the single widget I am opening when the app initially loads so the user can start typing in a restaurant name without having to click on the widget to give it focus?  I did get the focus set on the textinput box using focusManager.setFocus(tiSearch), but I still have to click on the widget itself before it gets focus from the application.  Once the widget header has been clicked I can start typing, but I would REALLY like to avoid that initial mouse click requirement if possible.

Thanks,
-Keith
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Keith,

   Sure you can it is just a couple of quick changes to code.

In the index.mxml add a script block:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:viewer="com.esri.viewer.*"
                xmlns:managers="com.esri.viewer.managers.*"
                pageTitle="Blah Blah"
                creationComplete="init()">
  <fx:Script>
     <![CDATA[
         protected function init():void
         {
             navigateToURL(new URLRequest("javascript: document.getElementById('index').focus();"), "_self");
         }
     ]]>
  </fx:Script>

This give the flash application itself focus from the browser. Then in the init function of my widget I want to have focus I just add this line:

txtSearch.setFocus();

You can see this working on my site http://gis.calhouncounty.org/ParcelViewer2.5/
as you are able to type in the parcel search widget without clicking (once the TOC is done loading).

Don't forget to click the Mark as answer check on this post and to click the top arrow (promote) as shown below:

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Keith,

   Sure you can it is just a couple of quick changes to code.

In the index.mxml add a script block:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:viewer="com.esri.viewer.*"
                xmlns:managers="com.esri.viewer.managers.*"
                pageTitle="Blah Blah"
                creationComplete="init()">
  <fx:Script>
     <![CDATA[
         protected function init():void
         {
             navigateToURL(new URLRequest("javascript: document.getElementById('index').focus();"), "_self");
         }
     ]]>
  </fx:Script>

This give the flash application itself focus from the browser. Then in the init function of my widget I want to have focus I just add this line:

txtSearch.setFocus();

You can see this working on my site http://gis.calhouncounty.org/ParcelViewer2.5/
as you are able to type in the parcel search widget without clicking (once the TOC is done loading).

Don't forget to click the Mark as answer check on this post and to click the top arrow (promote) as shown below:

ChrisSergent
Regular Contributor III

What file is the splash screen kept in?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Chris,

    The widget is called Splash and the widget file is SplashWidget.mxml

KeithPalmer
New Contributor
Thanks Robert.  I assumed you would be the one to have the answer.  I was so close.  I just forgot the 'creationComplete="init()">' part.

-Keith
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Keith,

Glad you got it working. Don't forget (the most important step) to click the Mark as answer check on this post as shown below: