cancel
Showing results for 
Search instead for 
Did you mean: 
WarrenBelz

Search and autofill in text box based on list values

We are all used to web searches giving suggestions of possible values you want and Combo Boxes have a Search function, but Text inputs do not have anything built-in for this, so it should be useful to have this function as well.

In the example below, the user starts typing and all matching values come up below. At any time they can press Enter and have the first (or only) matching value populate automatically in the Text Box.

AutoFillList.gif

The process involves only three things - changes to the OnChange and Default of the Text box and a Label below. This example is from a test list I have, but will work on any list subject to size Delegation on the Distinct function in the Label (I am sure there are work-arounds if this is an issue).

Firstly, the OnChange of the example Text Box (txtManName) is

With(
   {
      wMatch: 
      If(
         !IsBlank(Self.Text),
         LookUp(
            Devices,
            StartsWith(
               ManufacturerName,
               Self.Text
            )
         ).ManufacturerName
      )
   },
   UpdateContext(
      {
         varMatch: 
         If(
            !IsBlank(wMatch),
            wMatch,
            Self.Text
         )
      }
   )
)

So a Variable is being updated to the first matching value (if present) in the list or if not present the existing text.

The Default of the Text box is

If(
   !IsBlank(varMatch),
   varMatch
)

If this is being used in a form to also display existing records, you would add

If(
   !IsBlank(varMatch),
   varMatch,
   Parent.Default
)

and also reset varMatch at Screen OnVisible and possibly on Form submit.

UpdateContext({varMatch:Blank())

The last bit is the Label Text

If(
   !IsBlank(txtManName.Text),
   With(
      {
         wResult: 
         Concat(
            Distinct(
               Filter(
                  Devices,
                  StartsWith(
                     ManufacturerName,
                     txtManName.Text
                  )
               ),
               ManufacturerName
            ),
            Result & ", "
         )
      },
      Left(
         wResult,
         Len(wResult) - 2
      )
   )
)

The reason for the With() statement is to get rid of the last comma.

I hope this is useful for you as an alternative to using a Combo Box

Comments

Hi @WarrenBelz ,

 

I have a table in Excel and I used your above formulas.  I changed "ManufacturerName" to Description (this is the title of the column I need it to search in) and I changed "Devices" to Inventory (this is the name of my table).  I changed txtManName to TextInput8.  When I run the app it does not pull up the names I have in the description column.  If I type an A in the text box, an A pops up in the label box and nothing else happens.  I also copied those formulas to different cards on a Scollable Screen and when I enter text into 1 box, all the boxes show the same value.  Any tips?