Hi
I have a form which is based on an XML datasource.
At the moment I can bind a field to a particular occurrence of an element - eg: $.element1[3].fieldname1
or to an element that matches a certain conditions - eg: $.element1.[fieldname2 == "blah"].fieldname1
What I want to do though is to count back from the last occurrence of a field, so something like $.element1[n-5].fieldname1 where n is the total number of occurrences of element1.
Does anyone know if there's a way to do this?
Thanks
Dan
Views
Replies
Total Likes
Hi Dan,
I am not sure I get where you are coming from, but if the element is repeating then you can access the instance of the element using the instanceManager.
.count gives the total number of instances stating at 1,
whereas
.index gives the number of a particular instance using a zero based numbering system.
var oNodes = element1.instanceManager.count;
Hope that is of some use,
Niall
That gets me closer.
I can do something like: $.element1.[this.index==3].fieldname1 which I think is equivalent to $.element1[3].fieldname1.
Unfortunately any references to count or this.count still get me an error.
Views
Replies
Total Likes
Okay,
If element1 is the repeating object, then I would not have expected $.element1.[this.index==3].fieldname1 to have got you to the particular instance.
In Javascript once you have an instance number you want to use/reference you would resolve the node:
var i = _element1.count; // the underscore '_' is shorthand for instanceManager
var myData = xfa.resolveNode("element1[" + i + "]").fieldname1.rawValue;
If you wanted the third last instance you would subtract 3 from i before resolving the node.
The script above is Javascript.
The reason this.index works is that all objects have an index, zero-based. So for an object (textfield) on a form with this javascript in the calculate event:
this.rawValue = this.index; // will return "0" because it is the only instance of an object with that name
this.rawValue = this.instanceManager.count; // will return "1" because count is not zero based.
I hope that helps,
Niall
Thanks a lot.
I think the basic answer here is that I'm trying to fit a bit too much into the Data Binding field. I'll use that _elementName.count thing you suggested in a event and populate the values programmatically instead.
Cheers
Dan
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies