First of all, to trigger interaction code when a user has a Text Field widget in focus and presses the Enter key, you’ll need to create a “Submit button” (it can be any widget; if you don’t want it to be seen, I recommend using a Hot Spot widget.) Right-click on the Text Field widget and select “Assign Submit Button” or in the INTERACTIONS pane, Look at the “PROPERTIES” area, click “Show All” to expose the “Submit Button” droplist. Create your interaction code on this widget.
I’ll assume you are using repeater filters for your predictive search feature. When you apply a filter, you are limiting the available items (rows) in the repeater, so you will need to refer to the first item in your filtered list. You can do this with the expression, [[Item.index]] equals "1"
.
Axure does not make it easy to refer to widgets (or their text values) in a specific row of a repeater. This has frustrated Axure users for many years, ever since they introduced the repeater. There are two methods I know of to do this:
-
Listener Method
- A bit of a hack, but it works
- On a widget in your repeater, assign an otherwise unused event, such as Moved or Rotated --this will be your “listener event” that you can trigger whenever you need. The important thing to realize is when you call this event, it will be performed for every available row in your repeater (in rapid succession from the first to the last row.)
- To refer to a single row, each widget instance will need to compare itself to a target value–thus “listening” for itself to be called–and trigger actions only if it matches the target value.
- In your example, your repeater widget (logically, this would be the widget containing the text) would have a conditional case of:
If [[Item.index]] equals "1"
Set Text of MyTextFieldWidget to [[Item.Column1]]
//where ‘Column1’ is the name of the column containing the text value
- Your submit button’s Click or Tap event would have an action to
Move MyRepeaterTextWidget by (0, 0)
or
Fire Event MyRepeaterTextWidget fire Moved
-
Special Column Method
- Create a column in your repeater datasheet to control which row to pull data from. When the value of this column is set to a specific value, like “true” or “1” it can trigger a special event, like setting the text of your text field, either as a named widget or a focused widget (useful if the same thing can be done for multiple widgets that can call it.)
- In your example, you could create a column named, “AutoFill” --leaving this column blank for all rows.
- In the repeater’s Item Loaded event, create a conditional case like,
If [[Item.AutoFill]] equals "true"
Set Text of MyTextFieldWidget to "[[Item.Column1]]"
Update Rows This to "false"
- On the submit button’s Click or Tap event, set
Update Rows MyRepeater set AutoFill to "true" where [[Item.index == 1]]
//of course, it is important to call this after you’ve filtered the repeater. This would be the case if you apply the filter with the Text Field’s Key Up event. If you’re using the Text Changed event, cut & paste that code to the Key Up event.
- Then you can hide the repeater, etc.
I prefer the latter method because it is not a hack, and it makes the interaction code easier to see and maintain–in the repeater’s Item Loaded event, shown in the INTERACTIONS pane when the repeater is selected, rather than having to open the repeater and click around on widgets to see if there are “secret listener events” set up.