Expand my Community achievements bar.

SOLVED

Get text.value fully dynamically (getAttribute)

Avatar

Former Community Member

Hi,

I have a subroutine which should get any element attribute dynamically, based on attribute name. Simplified version would be as:

function getElementAttribute(iElement, iAttributeName) {
  getElementAttribute = iElement.getAttribute(iAttributeName);
}

This works good, except that I don't know how to get text field value fully dynamically. Static and semi-dynamic code that works would be:

getElementAttribute = iElement.value.text.value; //fully static
getElementAttribute = iElement.resolveNode("#value.#text").value; //semi-dynamic

However, I can't make it in fully dynamic and generic way, without static attributes.

Here are my unsuccessful attempts:

iElement.resolveNode("#value.#text").getAttribute("value");
iElement.resolveNode("#value.#text.#value");
iElement.getAttribute("rawValue");
iElement.getAttribute("value.text.value");
iElement.getAttribute("#value.#text.#value");

Does anyone know solution to this?

Thanks!

KR,

Igor Barbaric

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I might be off track here, but if iElement is the JavaScript object that references the form element the iElement["rawValue"] will return the rawValue.  So you could replace the string literal "rawValue" with a variable?

Hope this helps

Bruce

View solution in original post

8 Replies

Avatar

Level 8

Does simply iElement.rawValue not work?

Kyle

Avatar

Former Community Member

Hi, Kyle,

Maybe this works maybe not, but this is not what I need. Perhaps I wasn't clear enough so I'll try to elaborate more:

iElement.rawValue is a static way to get attribute value for rawValue. In other words, the name of the attribute rawValue is typed directly in the source code. This is not what I need.

I need a way to get an attribute value by using a variable which contains name of any given attribute. To simplify code for test and research purpose, I first used literals enclosed in double-quotes, such as (note that this doesn't work):

iElement.getAttribute("rawValue")

If I manage to make it work in this way, then I'll replace literal "rawValue" with a string variable, for example:

iElement.getAttribute(stringAttributeName);

enabling access to attribute whose name is contained in variable stringAttributeName. This worked for most of the attributes that I needed, but I can't make it work for text value, which you can statically get as iElement.value.text.value

KR,

Igor

Avatar

Level 8

Ok I understand now.

That is a tough one. What I think is happening here is that when the methods getAttribute, resolveNode, even getElement are used to access a property/attribute/node it is under the context of the Form DOM in which they are trying to access those properties but in fact rawValue and value (the last 'value' in value.text.value) are actually defined in the SOM (scripting object model) not the Form DOM. I don't know of any method that would access the SOM for it's properties since referencing those propertiese would always be done at design time anyways (for all form building purposes anyways).

You could use iElement.resolveNode("value.text").value  Here "value.text" is the actual node your looking for and .value is the SOM accessor used to get the string content of that node.

Again, this is my interpretation of what is happening.

Hope that helps somewhat.

I'd love to hear from anyone else on the subject...

Kyle

Avatar

Correct answer by
Level 10

Hi,

I might be off track here, but if iElement is the JavaScript object that references the form element the iElement["rawValue"] will return the rawValue.  So you could replace the string literal "rawValue" with a variable?

Hope this helps

Bruce

Avatar

Level 8

Ah, of course! Well that was easy. Didn't even occur to me.

Thanks Bruce.

Kyle

Avatar

Level 10

Yeah, it's easy to forget about the JavaScript stuff when you are thinking XFA, Bruce

Avatar

Former Community Member

Hi, Bruce!

This is what I was looking for - works exactly as I want. Thank you very much for your help!

KR,

Igor

Avatar

Former Community Member

And on that note, how do I create a PDF in LiveCycle designer that is editable in Adobe Reader 8-10?  I'm sorry to be posting this question in an existing thread, but the site isn't allowing me to post a new thread.  Thank you.