Skip to main content
deckarduk
Inspiring
January 25, 2021
Answered

getNthFieldName() query

  • January 25, 2021
  • 2 replies
  • 2673 views

Hi there,

Please can someone help.

I'm trying to write a script to change the properties of a group of checkboxes on a page.

Besides checkboxes there are text fields too.

The checkboxes aren't necessarily named the same however, they're close to each other and they sit on the same vertical line from the bottom of the page.

I'm trying to loop through each field item using getNthFieldName() and from there I can get the position of each checkbox.

Only thing is even though the checkboxes are close to each other, as you read from left to right on the page, looping through the fields produces a different order?

I've tried changing the tab order to 'by row' but this has no effect on order of the list when looping though the fields and using getNthFieldName().

Does the reading order, or tab order, have no bearing on the way the fields are returned using the method below?

 

for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);

}

 

Thanks in advance.

 

This topic has been closed for replies.
Correct answer Bernd Alheit

There is no connection with reading order or tab order.

2 replies

try67
Community Expert
Community Expert
January 25, 2021

You can analyze the rect property of the fields to determine their distance from each other.

deckarduk
deckardukAuthor
Inspiring
January 26, 2021

Hi Try67,

Thanks for the help.

Yeah, I was going to look at the rect property to see if the checkboxes were all in a horizontal line by checking the vertical position from the bottom of the page.

I'd asked the question because early tests showed looping through the fields, using this.getNthFieldName(i), didn't return them in left to right order even though I had tab by row selected.

I need to check again to see if each group of checkboxes I'm to hit fall together when returned by this.getNthFieldName(i).

Thanks again the help.

try67
Community Expert
Community Expert
January 26, 2021

Don't rely on the order in which getNthFieldName returns values for anything. It doesn't even have to be in page order. You get a field from page 1, then 5, then 1 again, then 3, etc. If you want the fields in a specific order you have to sort them yourself, but you can't do that based on tab order, since there's no such property in the JS API, unfortunately.

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
January 25, 2021

There is no connection with reading order or tab order.

deckarduk
deckardukAuthor
Inspiring
January 25, 2021

Hi Bernd,

Thanks for the confirmation.