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.
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.
19 Comments
Joeri Blomberg
This is very useful. Thanks for sharing!
Daksh Darji
What is ManufacturerName and Devices here ? Is it excel backend data header and backend data excel’s table name ?
Warren Belz
Yes – just a test list I have of PC types. You can apply this to any list you have
Charles Chen
Thanks for your sharing. It’s really helpful. But I found an issue about formula of the Label Text when testing. I found error for “Result” on the line “Result & “, “”. I tried to fix the issue but fail. Would you mind help me check with it? Thanks again.
Warren Belz
It is simply joining the Distinct value with a comma – you might check your brackets etc.
Charles Chen
My mistake. fixed. Thanks anyway.
Claudia
very nice idea! Thank you for sharing it!
How can you reset the label text, when you move to a different field in a form?
Warren Belz
Hi Claudia,
I am not sure what you mean – you are setting a Variable that is the Default of the Text box, so it will change with the Variable value.
Manoj
Plz change that Result variable to value or else it wont work
Warren Belz
That is a recent basically unannounced Microsoft change (see these release notes under a week ago. Result still works on existing code. I will wait for the fall-out of this before updating everything.
Warren Belz
That is a recent basically unannounced Microsoft change (see these release notes) under a week ago. Result still works on existing code. I will wait for the fall-out of this before updating everything.
Oren Galiki
Hi,
Thanks so much.
The Result part : Result & “, ” shows an error that indicates that it is not recognized.
I have followed each step to make sure everything is coded.
I have also reviewed the previous comment, and there is not solution for the issue..
Can you clarify how this can be solved?
Warren Belz
As noted in the last comment (before yours), Value is not the valid reference – I have now updated the post.
Bill Fry
Easier than using a dropdown or combox box, but my issue is, I am using this in a repeating table in power apps. I have Add your code with no errors, but when I run the collection, it does not display the items in that SharePoint List. If I save to add a new repeating line, what was type in there remains. Any ideas? Here is the code I used:
With(
{
wMatch:
If(
!IsBlank(Self.Text),
LookUp(
‘TMPC Job Names’,
StartsWith(
JobName,
Self.Text
)
).JobName
)
},
UpdateContext(
{
varMatch:
If(
!IsBlank(wMatch),
wMatch,
Self.Text
)
}
)
)
Warren Belz
You are going to have an issue in a gallery with the Default applying to every record, however it still should work providing varMatchis the Default. You might also add
If(ThisItem.IsSelected,varMatch)
, to capture only the current item, but you will find this a bit problematic when you switch records.Marie
Hi, Thanks a lot,
Need some help because when I use that, if I have some similar names, I can only select the first one presented in my list
For example, in my list I have :
abc
abbc
abbbc
In my textbox, when i write “ab”, i will see the 3 items but i can only select the fisrt one. How can i change that and allow the user to select “abbbc” for example
Hope is clear enough
Thanks in advance,
Warren Belz
Hi Marie,
The user just needs to keep typing = abbb would bring up the one you want.
Marie
But have we a possibility that the user can click on the proposition he want ?
Warren Belz
This is a Text box – if you want to choose an item, you would need a Combo Box (which supports this natively)