Changing all labels on a form using a loop

Hi everyone,

I have two tables with identically named columns: one to hold the data, and one to hold the actual text/display names of the field labels (2 records, 1 for English and 1 for French). Using a relationship via a global, I can switch from one language to another methodically if I set each labels dataprovider to point to the label name via the relation.

My (newbie) question is: Instead, how can I loop through each label to show the text in the language chosen via the global and the realtionship?

Any help appreciated - I searched the forum for a similar post, but came up empty, so I’m sorry if this question has already been answered here.

TIA,

Ben

//process all named elements on a form
for ( var i in elements ) {
	//name labels that you want to process with prefix of "lbl_..."
	if (elements[i].getName().substring(0,3) == "lbl") {
		//assign a data value to the text property of a label
		elements[i].text = relationshipName.fieldName
	}
}

WOW! :o

Thanks a lot David. How can I make sure that the correct field content gets placed on the corresponding labels using “relationshipName.fieldName”? I would imagine I have to set that to a variable also, and loop through each iteration… :?:

Ben

I usually derive the field real name from the name I give it. Assuming you want the label data provider to be set to “group_name”, name the label “lbl_group_name”. Then this assignment will work:

elements_.text = relationshipName[elements*.getName().substring(4)]*_
_*```*_

A couple more notes:

With this naming convention a small block of code can be used to set as many labels on a form as you want.

And processing the whole element tree means you don’t have to assign a method to each individual label you put on the form – just attach the method to the form onRecordSelection() event.

Real powerful stuff, David! I just jnew there had to be a way to achieve this, but I was missing some pieces of the puzzle. :oops:

Thanks again for your clear and detailed explanations - much appreciated.

Cheers,

Ben