My form has repeating instances. In some cases the addes instance is almost exactly like a previous instance. I would like an addInstance that would add the instance with the information from this.parent.index field if that is possible.
So when clicking on add instance it would prompt the user for the line number to be copied. If that's not possible, then copying the last line entered would be the workaround.
This is the last major piece of the puzzle for this form. The add instance I'm using now looks like....
this.resolveNode('Subform3.Subform2._Subform1').addInstance(1);
if
(xfa.host.version < 8) {xfa.form.recalculate(1);}
Thanks -pc
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
Here is the form back to you:
https://acrobat.com/#d=W1ahUb9VljMPZ2h3HisngA
There were a few issues:
I have removed the resolveNode, so you can have a look at this. I would recommend naming objects as you drag them onto the form. Mainly because if you name them after, you will have to work back through your script and change the references.
In the line number, I have added a "+1" to count for the zero-based index. I have also moved the script to the layout:ready event, so that as instances are removed the numbering will be corrected.
Hope that helps,
Niall
Views
Replies
Total Likes
Hi,
I have an example here, where on click a new instance is added and the value of the "Send to" is inserted into the value of the "Reviewer" in the new instance.
https://acrobat.com/#d=HD6XJ1qofZDf713Yq1P43g
Not exactly what you want, but it should be close enough to show the process/script.
Also if you name subforms, with different names, then you will not need to resolve the node.
I am heading out for a walk and will have a think about specifing the row that needs to be copied.
Niall
Views
Replies
Total Likes
Not working but I may be close?
form1.Subform4.Button2::click - (JavaScript, client)
this.resolveNode('Subform3.Subform2._Subform1').addInstance(1);
if
(xfa.host.version < 8) {fa.form.recalculate(1);var
lastRow = Subform1.count - 1;
var
secondLastRow = lastRow - 1;
var
oItem = xfa.resolveNode("form1.Subform3.Subform2.Subform1[" + secondLastRow + "]").TrussType.rawValue;
// add the item to the dropdown
xfa.resolveNode("form1.Subform3.Subform2.Subform1["
+ lastRow + "]").TrussType.addItem(oItem);// set the value of the dropdown
xfa.resolveNode("form1.Subform3.Subform2.Subform1["
+ lastRow + "]").TrussType.rawValue = oItem;}
If i can get one of the fields to copy down (TrussType) I can figure out the rest.
http://share.planswift.com/download/?file=Y8XDGYQZ-ZKCK-NV6M-ILZA-XWM7LKTDNWW
"Also if you name subforms, with different names, then you will not need to resolve the node."
Once I get these last two items working I will circle back and try to fix this issue.....
Thanks,
-pc
Views
Replies
Total Likes
Hi,
Here is the form back to you:
https://acrobat.com/#d=W1ahUb9VljMPZ2h3HisngA
There were a few issues:
I have removed the resolveNode, so you can have a look at this. I would recommend naming objects as you drag them onto the form. Mainly because if you name them after, you will have to work back through your script and change the references.
In the line number, I have added a "+1" to count for the zero-based index. I have also moved the script to the layout:ready event, so that as instances are removed the numbering will be corrected.
Hope that helps,
Niall
Views
Replies
Total Likes
Hi,
I have mocked up an example, which uses the response method to ask the user which row they want to copy.
It is available here: http://assure.ly/fdwtIv
Hope that helps,
Niall
Views
Replies
Total Likes
Thanks Niall the copy last line works great.
If you get any ideas on how to copy a specific line that would be cool.
I did loose the functionality of the line count object.....see attached.
http://share.planswift.com/download/?file=NXVV67E8-D1LC-1TJO-T3IM-VI8FSGD6NLC
Thanks for all your help!!! I couldn't have made it through this without it.
-pc
Views
Replies
Total Likes
Hi,
When I moved the script to the layout:ready event I didn't check it. Because the language is set to javascript it is missing "this.rawValue = " at the begining.
Please change it to:
this.rawValue = this.parent.index + 1;
It should work then.
I added in the "+1", because the index is zero-based, but you probably want the line numbers to start as "1".
I have the working example of where the user can select the row to copy here: http://assure.ly/fdwtIv.
Hope that helps,
Niall
Views
Replies
Total Likes
I actually figured the one index myself belive it or not...
I've tried to extrapolate your example on copying a line but can't get it to run...am I close? I know my subform naming is causing this to be more difficult than it is probably....and the fact that I'm not very good at this (yet) doesn't help either...here is where I am....
form1.Subform4.Button3::click - (JavaScript, client)
// set up the question, based on the current number of rows
var
vQuestion = "Select which row you want to copy. \n\nEnter a number between 1 and " + Subform3.Subform2._Subform1.count + ". \n\nClick Cancel if you do not want to copy an existing row.";
// add the new row
// '_' is shorthand for instanceManager, eg '_Row1'
Subform3.Subform2._Subform1.addInstance(
true);
// ask which row the user wants to copy
var
vTarget = xfa.host.response(vQuestion, "Copy a row") - 1;
// new row
var
vNewRow = Subform3.Subform2._Subform1.count - 1;
if
(vTarget >= 0 && vTarget < Subform3.Subform2._Subform1.count)
{
// copy the value of the dropdown in the selected row
var oItem = xfa.resolveNode("form1.Subform3.Subform2.Subform1[" + vTarget + "]").description.rawValue;
// set the value of the dropdown
xfa.resolveNode("form1.Subform3.Subform2.Subform1["
+ vNewRow + "]").description.rawValue = oItem;
xfa.resolveNode("form1.Subform3.Subform2.Subform1["
+ vNewRow + "]").description.execEvent("exit");
}
else
if (vTarget == null || vTarget == -1)
{
// do not copy, but also do not give audio feedback
}
else
{
xfa.host.beep("1");
// warn the user if number is outside range
}
Views
Replies
Total Likes
Hi,
You need to change the script so that it is referencing objects in your form. For example "description" is the name of the dropdown in my form. You need to change this to the name of the object inyour form for the script to work.
Niall
Views
Replies
Total Likes
Am I getting close?
// set up the question, based on the current number of rows
var
vQuestion = "Select which row you want to copy. \n\nEnter a number between 1 and " +
form1.Subform3.Subform2._Subform1.count
+ ". \n\nClick Cancel if you do not want to copy an
existing row.";
// add the new row
// '_' is shorthand for instanceManager, eg '_Row1'
form1.Subform3.Subform2._Subform1.addInstance(
true);
// ask which row the user wants to copy
var
vTarget = xfa.host.response(vQuestion, "Copy a row") - 1;
// new row
var
vNewRow = form1.Subform3.Subform2._Subform1.count - 1;
if
(vTarget >= 0 && vTarget < form1.Subform3.Subform2._Subform1.count)
{
// copy the value of the dropdown in the selected row
var
oItem = xfa.resolveNode("form1.Subform3.Subform2._Subform1[" + vTarget + "]").TrussType.rawValue;
// set the value of the dropdown
xfa.resolveNode("form1.Subform3.Subform2._Subform1["
+ vNewRow + "]").TrussType.rawValue = oItem;
xfa.resolveNode("form1.Subform3.Subform2._Subform1["
+ vNewRow + "]").TrussType.execEvent("exit");
}
else
if (vTarget == null || vTarget == -1)
{
// do not copy, but also do not give audio feedback
}
else
{
xfa.host.beep("1");
// warn the user if number is outside range
}
Views
Replies
Total Likes
Hi,
In my example there is script in the exit event of the description dropdown. This is why I have the line execEvent("exit"). If you do not have script in your TrussType dropdown, then you do not need that line of script.
What is happening when you click the button?
When debugging you should open the JavaScript Console (Control+J). When you click the button, if there is a problem with the script it may show up in the console.
Also In the Script Editor window there is a "check syntax" button at the top. If you click this it will highlight errors in the script in red.
Looking at the script the main error I see is that in the lines where you are resolving the node to the particular instances of the subform you have the underscore ("_") in front of the Subform1 reference. This is an error, you only need the underscore where you are calling the instanceManager, for tasks such as .count, .addInstance, .removeInstance, etc.
There are three locations where you are resolving the node, I am just showing one corrected line here, without the _ in front of Subform1:
xfa.resolveNode("form1.Subform3.Subform2.Subform1[" + vTarget + "]").TrussType.rawValue;
Hope that helps,
Niall
Views
Replies
Total Likes
Awesome - working fine now .... did a script syntex check and found the problem right away.
Think I'm good to go....Thanks for all your help!
Views
Replies
Total Likes