Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to get CAPTION of a field?

Avatar

Level 8

Hello

I am trying to get the TextField1's CAPTION/LABEL/DESCRIPTION (what text user sees on the form, say 'Account #') with the below code but its not working, pls. let me know the syntax to get it

var a;

var b

if (xfa.resolveNode("("VISITOR.PAGE1.Subform1.TextField1").rawValue == null) {
a = xfa.resolveNode("VISITOR.PAGE1.Subform1.TextField1").name;

b = xfa.resolveNode("VISITOR.PAGE1.Subform1.TextField1").id;

{
app.alert( b + " is a required field")
}

}

Thank you

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,

You can assign or check the value of a field's caption by using:    SOM.caption.value.text.value

if (TextField1.caption.value.text.value == "Text Field1")

{

app.alert("Hello World");
}

That means you can assign the caption to a variable.

In some cases you will need to use the resolveNode() method as is  required by the relative SOM and your naming objects. It is not required in many situations.

Also, the "name" attribute of a field can be accessed by using:    SOM.name  (I haven't tried assigning a new value to the "name" attribute)

As for an .id attribute -- I don't think they exist in xfa.

Good luck!

Stephen

View solution in original post

4 Replies

Avatar

Correct answer by
Level 7

Hi,

You can assign or check the value of a field's caption by using:    SOM.caption.value.text.value

if (TextField1.caption.value.text.value == "Text Field1")

{

app.alert("Hello World");
}

That means you can assign the caption to a variable.

In some cases you will need to use the resolveNode() method as is  required by the relative SOM and your naming objects. It is not required in many situations.

Also, the "name" attribute of a field can be accessed by using:    SOM.name  (I haven't tried assigning a new value to the "name" attribute)

As for an .id attribute -- I don't think they exist in xfa.

Good luck!

Stephen

Avatar

Level 8

Thank you.

Do i need to use SOM in my syntax or not? Say, i hv like below

my_form

my_page

my_subForm

my_text_field1 ===> caption is my_caption

Then how should i get my_caption for my_text_field? syntax pls.

THank you

Avatar

Level 7

You can use a relative-SOM or an absolute SOM

The Script Editor makes it easy by letting you CTRL (relative SOM) or CTRL + Shift (absolute SOM) and click on the object you are referring to. First put the cursor in the Script Editor where your script is. Then, while the cursor is blinking ready for you to type your script, press CTRL and click on the object you need the SOM for.

my_form.my_page.my_subForm.my_text_field1  (absolute SOM for my_text_field1 )

so:

my_form.my_page.my_subForm.my_text_field1.caption.value.text.value //references the my_text_field1 caption using an absolute SOM

or:

my_text_field1.caption.value.text.value //references the my_text_field1 caption using a relative SOM (when the object with the script you are writing is in the same subForm as my_text_field1)

Good luck!

Stephen

Avatar

Level 8

Thank you for ur detailed answer, it worked.