5 Replies Latest reply on Mar 2, 2010 11:46 AM by pguerett

    Set Focus target when Add New Instance


      [LC Designer ES2 9.0] Using Action Builder to add a new instance of subform SITE, where first field is called SiteName.


      If I set action to Set Focus to SiteName, the focus goes to the *original* SiteName field instead of to the new instance.


      Users will typically add a number of additional sites and, each time, I want the focus to be set on the first field of the newest instance, not the original instance. How do I accomplish that? Thanks!           ~Carol

        • 1. Re: Set Focus target when Add New Instance
          pguerett Level 6

          This is not as easy as it sounds. The ability to move the cursor to a new field is an AcroForm level command. When you add an instance of a subform the objects do not exist on the AcroForm side until the script is finished. In your case you want to mmove the cursor in the same script that will add the subform so the standard cursor reposition command will not work (as the new field dose not exist yet). There is an acroform command that will allow you to execute a command in the future (presumably when the script is finished and the objects actually exist). Unfortunately you must use the acrofom name to address the field. Here is a snippet of code that shows you the command that you need to use. Note that you will have to replace the object names with your own (the one that is between the single quotes):


          var setField = app.setTimeOut("this.getField('form1[0].Page3[0].TextField4[0]').setFocus();", 1);




          • 2. Re: Set Focus target when Add New Instance
            Carol_H Level 1

            I understand the concept (I think...), but am not clear on where to place the code.


            I used Action Builder to create an AddSite action: when check box chkAddSite is checked | Add a new instance of subformSiteInfo | and set visibility of subformSiteInfo to visible. Does your code go in that same action sequence? If so, what is the next Action Builder result selection? If not, where do I insert it?


            I never know whether the new instance of the subform will begin on the following page, so the user might keep clicking the chkAddSite box, thinking it didn't work. Although, thinking this through, maybe I could force the new subform instance to always appear at the top of the following page, and somehow direct the focus there, rather than to the specific first field???


            Thanks!         ~Carol

            • 3. Re: Set Focus target when Add New Instance
              pguerett Level 6

              I assume that you are activating the subform instance by clicking a button. The code would go on the click event of that button. There will be code there from the action builder so simply add it to the bottom of that script.


              Your other idea wodul be fine. You coudl put a small 1pxel by 1 pixel field at the top of the page and simply set the focus to that field (it will already exist). Just make sure that you turn off the borders and captions and make the background and foreground color of the field the same as the background color of the form so that the field is not discernable by the user.


              Hope that helps


              • 4. Re: Set Focus target when Add New Instance
                Carol_H Level 1

                Unfortunately, I am still having trouble with this.


                My goal (see attached): When btnAddProgramInfo is clicked, add new instance of subProgramInfo at the top of next (new) page and set cursor focus to txtServiceProgName in the new instance.


                The section before Program Information will be multiple/unknown number of pages


                Each completed Program Information section could span several pages, and users could need to add as many as 20 programs. There is nothing following the Program Info section.


                Sorry to be so dense, but I just can't seem to set the cursor focus in each new instance, no matter what I try.


                          Thanks in advance!           ~Carol

                • 5. Re: Set Focus target when Add New Instance
                  pguerett Level 6

                  There is no attachment ....can you send it to LiveCycle8@gmail.com