Perspective Set focus in Field of a Specific Instance of a FlexRepeater

I have a FlexRepeater repeating a row template containing 3 TextField.
The list of instances is bound to a database.
For each Field change event, a validation procedure is run and if it is ok, the focus is set to the next field and if it is not ok, the focus does not change.

Changing focus within the row field is working. Now I’m trying to send the focus to the first field of the next row.
I tried to use a message handler but I can’t find a way to reference a specific row in the flex repeater.

self.getChild(“flexRepeater”).getChild(“instance2”).getChild(self.session.custom.FocusedControlNext)

Any Idea if it can be done and how ?

You would need to pass the index of the row to the row itself so that it can include that information in the message.

Each row should listen for a message and act on that message based on its own index param.

system.perspective.sendMessage('SETFOCUSONNEXTROW', payload={"nextRowIndex": self.view.params.index + 1}, scope='page')

Then the listener for SETFOCUSONNEXTROW which is placed on the root container of your row template (and assuming the first Text Field component in each row is named "TextField"):

if payload['nextRowIndex'] == self.view.params.index :
    self.getChild('TextField').focus()

This won't ever work for addressing child instances of a repeater. The "children are just instances within this repeater - they are NOT separate components. The only way for the Flex Repeater to directly communicate with the instances it contains is through parameter passing. This is why my solution relies on the instances themselves to make an ephemeral broadcast which other instances can hear (as long as the scope is set to "page" for both the broadcast and the listener.

Thanks, it worked like a charm.

In my case, the name of the controls are dynamically supplied by the database and might be visible in some rows and others not. Therefore, the next control may vary for each field on each row and is also supplied by the database.
The control namenclature contains the row id so i decided to use that as a payload

This is the call after validation success.

payload = {"FocusControlNext":self.custom.FocusControlNext}
system.perspective.sendMessage("SetFieldFocus",payload=payload,scope='page')

And this is the response to set focus in the SetFieldFocus EventHandler:

#FocusControlNext name sample "tfLine[xx]_Field01"
focusControlNext = payload["FocusControlNext"]
fieldRow = focusControlNext.split('_')[0][6:]
if (fieldRow == str(self.view.params.Row.RowIndex)):
	field = self.getChild(focusControlNext)	
	if not field == None:
		field.focus()
		field.selectAll() #that still does not work... need to find how to make it work
1 Like