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(
   {
      _Match: 
      If(
         !IsBlank(Self.Text),
         LookUp(
            Devices,
            StartsWith(
               ManufacturerName,
               Self.Text
            )
         ).ManufacturerName
      )
   },
   UpdateContext(
      {
         varMatch: 
         Coalesce(
            _Match,
            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

varMatch

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

Coalesce(
   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),
   Concat(
      Distinct(
         Filter(
            Devices,
            StartsWith(
               ManufacturerName,
               txtManName.Text
            )
         ),
         ManufacturerName
      ),
      Value,
       ", "
   )
)

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

 

Comments