Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

FormCalc vs. JavaScript Question

Avatar

Former Community Member

Okay, so to be consistent throughout my form I'd like to use JavaScript throughout my form.  Additionally, it is easier to use.  Unfortunately, there's one behavior in FormCalc that I can't replicate in JavaScript, and I need it to work.  Here's the script in FormCalc

var vnum = _Body.count
var choice = xfa.host.messageBox("Warning! You are about to permanently delete this entry.  Are you sure you wish to proceed?", "Warning!", 3, 2)

if ((vnum==(this.parent.index+1)) & (vnum<>1) & (choice==4)) then
    Body[this.parent.index-1].Radio_Button_Subform.Radio_Button_Group.rawValue="2"
endif

if (choice==4) then
     _Body.removeInstance(this.parent.index)
endif

and here's my attempt to replace it using JavaScript

var vnum = _Body.count;
var choice = xfa.host.messageBox("Warning! You are about to permanently delete this entry.  Are you sure you wish to proceed?", "Warning!", 3, 2);

if ((vnum==(this.parent.index+1)) && (vnum!=1) && (choice==4))
     Body[this.parent.index-1].Radio_Button_Subform.Radio_Button_Group.rawValue='2';

if (choice==4)
     _Body.removeInstance(this.parent.index);

I've tested it out and I know the problem occurs with the line

Body[this.parent.index-1].Radio_Button_Subform.Radio_Button_Group.rawValue='2';

However, I don't understand why this reference is invalid in JavaScript when it worked in FormCalc, and I don't know how to make it work.

Thanks for your help.

1 Accepted Solution

Avatar

Correct answer by
Level 6

Hi,

For javascript version replace youre code with this one :

xfa.resolveNode("Body["+(vnum-2)+"].Radio_Button_Subform.Any_other_property_of_this_type").rawValue="2";

Also check attach, hope this is what you need.

BR

View solution in original post

10 Replies

Avatar

Level 6

Hi,

Try this one:

Body[this.parent.index-1].Radio_Button_Subform.Radio_Button_Group.rawValue="2";

BR

Avatar

Former Community Member

Unfortunately, that didn't work.  The green "BR" below the line of code wasn't relevant, was it?

Avatar

Level 6

Hi,

Yes, BR it is not part of the code.

If you'll post youre form I have a look at it.

BR

Avatar

Former Community Member

I'm posting my form below.  In case this gets queued, below are links to the Shrinking Text Field discussion as well as the form.

http://forums.adobe.com/thread/458209?tstart=0


http://forums.adobe.com/servlet/JiveServlet/download/2091082-13196/Pets%20with%20proper%20delete%20a...

(question-why are some web addresses displayed as links and others not in the forum?  It's difficult to use web addresses that aren't links.)

Look at the delete button.  I'll post the JavaScript version that doesn't work soon (I'm modifying the code a bit).

Avatar

Former Community Member

Here's the form with the delete button scripted in JavaScript as well as the same thing with the delete button scripted with FormCalc.  FormCalc works perfectly, but JavaScript has one problem.  If anyone has any comments about JavaScript conventions (tabbing, readability, whatever), I'd gladly take advice.  The problem line for the JavaScript one is the line that's commented out.  The message box above the problem line is to make sure the script is getting there.  As it is, when the bottom instance is deleted using the delete button, it will go away, but the value of the radio button group in the instance above it won't change to "no".  The only exception is when the bottom instance is the first line, then it works, but that's because there's no instances to deal with for that radio button group.  Everything else works the way I want it (at least the way I want it right now), so any help on this point would be awesome.  As you can see, using JavaScript yields a nicer script (shorter, one less variable, not redundant).

Avatar

Former Community Member

use double quotes instead of single quotes.  like this:

Body[vnum-2].Radio_Button_Subform.Radio_Button_Group.rawValue="2";

-rpeterson

Avatar

Former Community Member

I've tried it with single quotes, with double quotes, and with no quotes, and none of them work.  It seems like it should work with single quotes (I have the line

Yes_No_Base.rawValue

='1'

in the form and it works just fine.  I'm confused

Avatar

Correct answer by
Level 6

Hi,

For javascript version replace youre code with this one :

xfa.resolveNode("Body["+(vnum-2)+"].Radio_Button_Subform.Any_other_property_of_this_type").rawValue="2";

Also check attach, hope this is what you need.

BR

Avatar

Former Community Member

Thanks Paul, this works!  One last question-why do I need to use xfa.resolveNode and the [+vnum+] stuff?  I'm trying to figure out why this works and why the method I was using didn't, so I can figure out how to avoid problems like this in the future.

Avatar

Level 6

Hi,

In JS to take some node with index you have to use resolNode function.

BR