These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Formcalc or Javascript and how??

paalllikko
Registered: Jun 16 2009
Posts: 30
Answered

Now I'm having a problem with a button scripting. I would like to create button that copies a already existing subform (subform has 4 text fields and one check box) into the main subform.

I will try to describe the form for you:

Action field Responsible field Schedule field Situation field Ready Checkbox

button that adds another row of those fields.

I would like also to have another button that would remove wanted field. This button should be in every row individually.

I tried to find an answer from livecycle help and from acrobatusers, but didn't find help.

Could someone help me with the script???

Thank you in advance.

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
You have to set the binding of all fields in this subform to global.
Then you can use an addInstance()-script to create an exact copy of this subform.

See this example form:
https://share.acrobat.com/adc/document.do?docid=13bbd539-37f5-44d3-80d7-99337bd90d11

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

paalllikko
Registered: Jun 16 2009
Posts: 30
ok, now I got the subform to copy, but maybe I need to clarify my idea... I need to enter different data to the copied subforms fields than the first fields have? but now, if i change data in first subform, the second subform field changes too???

I'm doing a fillable form for operations planning, every row should have different operation written, and also, the forms should be possible to delete one by one also...

and, thank you for your help for the first problem, I hope you or someone else can help me with the next ones...
paalllikko
Registered: Jun 16 2009
Posts: 30
I figured out the deleting thing, that wasn't so difficult, but I'm still fighting with the problem of writing different information to the copied subform...
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
If you only want to dublicate the subform, but fill it each time with different content, you only have to set the binding of the fields from "global" to "normal" in the binding tab. ;-)

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

paalllikko
Registered: Jun 16 2009
Posts: 30
Thank your Radzmar very much. That solved my problem perfectly. Why didn't I figure that out.
paalllikko
Registered: Jun 16 2009
Posts: 30
Hey radzmar? Could you please help me with one more thing with this.... I have created also a deleting button by using remove instance, this is my code


SubformX.instanceManager.removeInstance(1);

but, if i have many rows of copied subforms, and I would like to remove some random/specific subform, the button always removes the first copy. It is because the (1) at the end of the script?

what could I do with the problem?
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
You have to place the remove button into the subform:

This script then removes the current instance of the subform.
_SubformX.removeInstance(this.parent.index);xfa.form.recalculate(1);

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

paalllikko
Registered: Jun 16 2009
Posts: 30
Amazing, thank you so much, and sorry for the inconvenience. You were great help.
paalllikko
Registered: Jun 16 2009
Posts: 30
Hello Razdmar, I'm not sure will this message come to you... but.... surprise, I have another problem.. Subforms are copied just the way I want them to... But now, I have Total-sum field in the end of all these rows, and I would like to create a field that calculates all of the Total-sum values together, regardless if there is 1 row with value or if there is 28 rows with some value?

Do you have any advice on this one?
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
You can try this method.
Create a numeric field called "TotalSumOfForm" and use this JavaScript in it's calculate event.

// Access a field in a repeating subform by looping through the node list.var oFields = xfa.resolveNodes("SubformX[*].Total-sum");var nNodesLength = oFields.length;var nSum = 0;for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {nSum += oFields.item(nNodeCount).rawValue;}TotalSumOfForm.rawValue = nSum;

Good luck

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs