Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Using setFocus from a SWITCH statement

Avatar

Level 4

Hi

Im trying to have my switch selections do a couple of things from one selection and am getting stuck on the correct syntax to use

below is a code example of what i'm trying to do - but basically i need a selection case "2" say, to (1) set various fields values from variables (2) set the focus event to a field (that relates to the choice)

here's an example of my (broken) code (orange below) - does anyone know the correct syntax for doing this? The field i want to force the focus/view to go to in a couple pages down (if that makes a difference)....

thanks

switch (this.rawValue) {

     case "8":

{cHist.presence = "visible";}

          break;

case "1":{

(page3.para1.rawValue = a1.value)

(page3.para2.rawValue = b1.value)

(page3.target.presence = "visible")

(xfa.host.setFocus(page3.target)

}

// the idea being to make the field visible then take the users focus to it once the variables have been set - i hope switch can do multiples and it's just my syntax (again) -- thanks for the help

         break;

case "2": {

(page3.para1.rawValue = a1.value)

(page3.para2.rawValue = b2a.value + ", which occured in " + page5.oneEBA.rawValue + ")." + b2b.value)

}

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

xfa.host.setFocus(page5.oneEBA);

View solution in original post

5 Replies

Avatar

Former Community Member

The case does not use braces "{}". See https://developer.mozilla.org/En/Core_JavaScript_1.5_Guide:Conditional_Statements

Try

switch (this.rawValue) {

     case "a":

          expression;

          expression;

          ...

          break;

     case "b":

          expression;

          ....

          break;

     default:

          break;

}

Steve

Avatar

Level 4

thanks steve,

it seems to accept this syntax:

case "5":

page3.para1.rawValue = d1.value + " " + page2.datedisqual.rawValue + "in the " + page2.courtdisqual.rawValue + " District Court";

page3.para2.rawValue = d3.value;    

xfa.host.setFocus.page5.oneEBA;

}

but the setFocus event is having no effect -- no sure why (I suspect it's failing silently for some reason.... or can focus not be set multi pages down?)
thanks

Avatar

Correct answer by
Former Community Member

xfa.host.setFocus(page5.oneEBA);

Avatar

Level 4

Hi steve,

thanks for the hep earlier, i just have one other (hopefully simple question, if you can spare a few minutes) - namely can you/how do you attach a switch statement to a field (exit event) that uses the rawvalue of another dropdown list to determine what to do (another syntax issue i guess)...

here's my issue/code:

  switch (worktype.rawValue)

case "1": {

page3.para5.rawValue = f1 + this.rawValue +".";

}

         break;

case "2": {

page3.para5.rawValue = f1 + this.rawValue +"222222.";

}

        break;

case "3": {

page3.para5.rawValue = f1 + this.rawValue +"3333";

}}

// this code being attached to a different field than worktype....
thanks for all the help, it's a greta help to the newbies
The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----