Autocomplete with set text as input on key down possible?

Hey everyone,

I’m new to Axure and I’ve created an input field with autocomplete according to a “predictive search” tutorial. Works great!

I’m now trying to recreate the behaviour of the Angular Material input element with autocomplete active first option (this one:

The behaviour I want: when typing and getting suggestions, I want to set the first autocomplete suggestion as input when pressing enter. In the linked example you can type “t” and get suggestions for “Two” and Three".
When you press enter the input will be set to the first suggested option, in this case “Two” (and it stays as input when you navigate to the next element). If you type “th” and press enter the input will be set to “Three”.

What do I need to do in Axure to achieve this exact behaviour? I find repeaters and variables still a bit confusing, what do I need to do to set the first suggestion as input text when pressing enter after the autocomplete suggestions are working as intended?

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)
      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.


Thank you so much, this solved it! :slight_smile:

I used the special column method because assigning true/false is exactly what I’ve been trying to do on my own but wasn’t able to “translate” into actions Axure understands. I wouldn’t have thought about using “item loaded” on my own and didn’t know you could leave a column blank.

Seriously, how do you learn how to do these things in Axure? I feel like most tutorials only enable me to replicate and the documentation isn’t giving me enough to work with. I knew how this should work logically but it seems impossible to figure out how to do these things in the software.

I agree the documentation and tutorials don’t convey enough information, especially about repeaters. I’ve learned things mostly on this Axure forum. …Searching for topics or posting questions. Also, a lot of trial and error, and playing around with things to figure out how they work.

Thank you, I guess I have to keep doing what I’m doing to get into it, then. :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.