Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Stopping processing inside an event

Avatar

Level 1

I have a question similar to this post:

http://forums.adobe.com/message/3287875

I am inside a click event (button push) in Adobe Forms in a JavaScript routine.  I want to exit conditionally.  The above message had no repy and other searches did not find what I need.

Example in pseudo-code:

----- data.SF1.BTN_SHOW::click: - (JavaScript, client) ---------------------------------------------

var x = 1;

xfa.host.messageBox ("Before");

if (x==1) {

  return;

}

xfa.host.messageBox ("After");

If x is not 1, I want to see two popups, if it is 1 only the first one.  I tried 'return', 'exit', 'break', 'quit' (and a few other possible commands).  Since I am not inside a function, 'return' does not appear to work.

Thanks in advance.  I find the forums hard to navigate, so I hope I get an answer and find this post...

Regards,

Wolfgang

3 Replies

Avatar

Level 7

why not just rewrite the code to:

xfa.host.messageBox ("Before");

if (x<>1) {

xfa.host.messageBox ("After");

}

Avatar

Level 1

Thanks for your help.

Because it was just an example.  If I have 20 checks to make, I do not want to indent 20 times.  There should be a fairly simple way to stop the processing of the script similar to a 'return' or 'return false' in a function...

Any other ideas how to skip the remainder of the script inside the event?

Edit:

I found a way (although ugly) to make it work for multiple checks.  For simplicity, I added a numeric text field 'INT' to the same subform where my button is, just so I can test a few different cases... In reality, the checks can be for different and unrelated things.

----- data.SF1.Button1::click: - (JavaScript, client) ----------------------------------------------

var i = 0;

i = this.parent.INT.rawValue; // Just to set i conveniently
xfa.host.messageBox( "i = " + i );


// Dummy loop (once)

for ( var dummy = 0; dummy < 1; dummy++) {
  if( i < 1 ) { // Check 1
    xfa.host.messageBox( "i needs to be at least 1, but it is " + i );
    continue;
  }
  if( i < 3 ) { // Check 2
    xfa.host.messageBox( "i needs to be at least 3, but it is " + i );
    continue;
  }   
  if( i < 4 ) { // Check 3
    xfa.host.messageBox( "i needs to be at least 4, but it is " + i );
    continue;
  }       
   
// Checks passed
  xfa.host.messageBox( "All checks passed, i is " + i );
}
xfa.host.messageBox( "Done" );

Now everything goes to the 'Done' part of the code, but only the ones where all checks pass go to the 'All checks passed' part. Even with 20 checks I will only have one indentation which is acceptable.  If nobody finds a more elegant way to exit the click event processing when I tell it to, I will stick with this construction.  The 'continue' acts like a 'return' when inside the 'for' loop.

I hope for a prettier solution though.

Regards,

Wolfgang

Avatar

Level 10

Hi Wolfgang,

You can define JavaScript functions within the click event, so maybe the code below is better?

function canContinue(i)

{

  if( i < 1 ) { // Check 1

    xfa.host.messageBox( "i needs to be at least 1, but it is " + i );

    return false;

  }

  if( i < 3 ) { // Check 2

    xfa.host.messageBox( "i needs to be at least 3, but it is " + i );

    return false;

  }   

  if( i < 4 ) { // Check 3

    xfa.host.messageBox( "i needs to be at least 4, but it is " + i );

    return false;

  }       

   

  return true;

}

if (canContinue(this.parent.INT.rawValue))

{

    xfa.host.messageBox( "All checks passed, this.parent.INT.rawValue is " + this.parent.INT.rawValue );

}

Regards,

Bruce