Expand my Community achievements bar.

Accessing form data via Javascript.

Avatar

Former Community Member
Hi,



I'm completely stuck. I have a form with a table with a row containing a textfields. I'm able to add rows to that table via JavaScript. No problem here. Now I want to populate a dropdown with the data entered into the textfield(s). And Here I'm completely stuck. I don't manage to find the instantiated rows with their Textfields.



The hierchy view shows form1>purchaseOrder>Table1>Row



I tried stuff like this:

'xfa.resolveNodes("xfa.form.form1.purchaseOrder.Table1.Row[0].TextField1").rawValue'

or

'xfa.form.form1.purchaseOrder.Table1.Row[0].TextField1'

to access the node or the field without succces.



Nor do I find the way to get a count of the instantiated rows, so I could loop through them.



Thanks in advance

(a desperate)

Steven
16 Replies

Avatar

Level 10
Tables can be confusing to use sometimes, especially through script!



I created a simple 3x3 table. That means I have a header row and three rows.



If you want to get to an element of that table, you can use the follwing syntax:



xfa.resolveNodes("form1.Table1.Row" + i + ".Cell1").item(0).rawValue;



where i is the row you are looking for.



Now the question is how do I know how many rows I have?



Since all the rows are really subforms from the Table1 subform, you can get the number of children from that object with the following script:



var objTable = Table1.nodes;

app.alert(objTable.length);



In this case you'll get 8 objects because there is really 4 rows (including the header row) and they each have a corresponding instance manager object called _nameOfSubform, but you should still be able to deduct the number of rows.



There might be a better way that I'm not aware of. Maybe the people in the Designer Forum would know.



Jasmin

Avatar

Level 9
Hi Jasmin/Steven



I don't have my machine with me at the moment, but here are a couple of points from memory:

The expression is not quite right if you're using "repeating" rows. I believe it should be:

// To get the value of a particular cell, called "Cell1"

xfa.resolveNode("form1.Table1.Row[" + i + "].Cell1").rawValue;

// Note: Node not Nodes, and square brackets.



If you want the number of rows, you can use the following expression:

var cells = xfa.resolveNodes("form1.Table1.Row[*].Cell1").rawValue;

var count = cells.length;

// Can't remember if it's length, size, or something else. Code inspector should get it right.

// You can also use the following to get at the i-th cell in the array of values:

var cell_value = cells.item(i);



You may need to tweak my code a little if my memory has not served me well.



Howard

http://www.avoka.com

Avatar

Level 2

Hello Howard ,

I am intrest in this script :

var cells = xfa.resolveNodes("form1.Table1.Row[*].Cell1").rawValue;
var count = cells.length;

Is there a way to filter the data in that field without looping the whole table.

Best regards

Avatar

Level 10
Howard,

I agree with your code there (xfa.resolveNode("form1.Table1.Row[" + i + "].Cell1").rawValue;)



but for some reason that didn't work. I had to use the code I posted instead.



I'm not sure if it's because of the table control or something, but the expression was a bit different than usual.



Jasmin

Avatar

Level 9
Hi Jasmin

Just tested this.

You do need to save the form as a dynamic pdf.



// Row count

var mynodes = xfa.resolveNodes("form1.page1.Table1.Row1[*].TextField1");

tfRowCount.rawValue = mynodes.length;



// Cell value

var cellvalue = xfa.resolveNode("form1.page1.Table1.Row1[" + i + "].TextField1").rawValue;



I can post this somewhere if you want.



Steven - note that you only need to use xfa.resolveNode if you have an embedded array parameter [..]. Otherwise you can just use form1.page1.Table1.Row1.TextField1. This will always get you the first row's value.



Howard

Avatar

Former Community Member
Thanks a lot. I knew it couldn't be that hard. I just didn't seem to find the right syntax. I got it to work.<br /><br />This is how I tested it:<br /><br />var mynodes = xfa.resolveNodes("form1.scripting.Table1.Row[*].txtRow");<br /><br />for(i=0;i<mynodes.length;i++)<br />{<br /> var cellvalue = xfa.resolveNodes("form1.scripting.Table1.Row["+i+"].txtRow").item(0).rawValue; <br /> FFResult.rawValue += " - "+cellvalue;<br />}<br /><br />And Jasmin's code did the job. I don't get the value if ommit the "item(0)" in the 'xfa.resolveNodes("form1.scripting.Table1.Row["+i+"].txtRow").item(0).rawValue'<br /><br />Anyhow thanks again<br />Steven

Avatar

Level 9
Hi

Just one other thing...

Don't declare a variable of "nodes" instead of "mynodes". "nodes" appears to be an implicitly defined variable, and if you try to use it, all sorts of weird stuff happens.

Took me 3 hours to find that one :-S

Howard

Avatar

Former Community Member
Hi,



I stumbled on a new problem.



This is what I want to do.

1.I have a table:tableEntry, I have a textField=txtDescription in a row=rowEntry and a button=btnRemoveRow for removing the row.

2. I have a tableTarget with rowTarget and within the row a dropdownlist=ddlTarget.

3. Now each time a add a row in the tableEntry and enter data txtDescription I populate the ddlTarget for each row in the tableTarget. That's why I needed the previous code. This works.

4. The user can now select a value from the ddlTarget.



5. A user now edits the data in txtDescription

6. The ddlTarget is updated with the edited value



Now my problem. When I look at the code on the click event on the btnRemoveRow for removing a row in the tableEntry I see this:

_rowEntry.removeInstance(this.parent.index);

so I presume that "this.parent.index" holds the reference for the row I'm working in. Thus when I add an "exit" event on my txtDescription field, I (should) know what row I'm working in via "this.parent.index". So I can loop through the rows in tableTarget and update the appropriate dropdown item.



But this doesn't seem to work. I really don't get how the DOM works in lifecycle designer.



this is the code I used to test:

form1.Page1.tableEntry.rowEntry.txtDescription::exit - (JavaScript, client)

xfa.host.messageBox(this.parent.index);



Steven

Avatar

Level 9
Hi Steven

Welcome to the wonderful world of Javascript.



Try this:

xfa.host.messageBox("Index:" + this.parent.index);



Not 100% sure why this works better, but it's something to do with Javascript's loose typing, and forcing index to be displayed as a string by concatenating.



Howard

http://www.avoka.com

Avatar

Former Community Member
DJEEZ!!!

It actualy works like this.



So my code worked all the time, but it's the messageBox that has a ...euh "feature" :-)



thanks

Avatar

Level 9
PS Like Jasmin says, you're probably better off posting this on the LiveCycle Designer Forum.

Avatar

Former Community Member
Can somebody help me to fill in a table in Javascript.

I tried this:

xfa.resolveNodes("data.TableView.BodyTable["+i+"].NAME").rawValue = "100";



It doesn't work.

Avatar

Former Community Member
b Setting Initial View Properties to override Workspace defaults



We are new to LiveCycle 8 (less than 3months experience) even though we have used or been using its predecessors for year.



We would like to limit the confusion of our end users by restricting what non-form specific data and operations they see and can perform when opening a form in LiveCycle ES Workspace. I.e., no Edit, File, Find, Measuring, and the likes. Some forms would be more restrictive than others. So what we are really looking for is some method by which we can, on a form by form basis, turn off certain of the menu items that appear or can be turned on when a form is opened.



Setting the Initial View properties on the form would be the ideal way. But even setting the properties programmatically would be helpful.



Any assistance is greatly appreciated.

Avatar

Former Community Member
hi i have problem in adding rows to a table in adobe livecycle. I'm able to insert just 7 rows after that it doesn't do anything. I want to add around 20 rows to a table. How can i do that.



Thanks in advance

Avatar

Former Community Member
In the binding tab do you have a max value set for your repeating subform?



Also is it trying to go across a page ...you would have to allow page breaks in th eparent subform before it woudl be allowed to break across pages.

Avatar

Former Community Member
hi paul i got the rows inserting even upto 50 rows after changing the Max=7 to Max=50 in the XML source. You can use Find option and find for Max and change the correct value..