# "How to create an auto updated FieldCompletionFunction

I'd like to have an InputField with "dynamic" word autocompletion from a list : if I start to type some letters in the field I want the autocomplete suggestion updated. To do that I use the following code :

ListOfName = {"Steve", "Stan"}
InputField[Dynamic[f], String, ContinuousAction -> True, FieldCompletionFunction -> (Select[ListOfName,     StringStartsQ[ToString[f], IgnoreCase -> True]] &)]


It almost works but "one step too late", the ContinuousAction option seems to take into account the last letter but one instead of last. Example : if I type "Ste" in the field the FieldCompletionFunction suggest "Steve" and "Stan". I need to add the "v" (so "Stev" to have only "Steve" suggested.

Any idea to solve this ?

Thank You !

You have several issues. One is that the list of names contains only a single name ("Steve, Stan"). The other is that you are using f in your function. It would be better to use a pure function instead, something like:

ListOfName={"Steve","Stan"}
InputField[
Dynamic[f],
String,
FieldCompletionFunction->Function@Pick[ListOfName, StringStartsQ[ListOfName, #]]
]


The ContinuousAction rule is superfluous for String types, as is the ToString.

• Thank a lot ! yes the missing " was a typo. Just to be sure (not everthing about Mathematica syntax is clear to me !) can you confirm that for parameters expecting a function (like FieldCompletionFunction) the argument (#) is the first parameter (Dynamic[f]) and so we don't need to use & to evaluate it explicitly? (This is because I did not understand this I was using f ). Mar 26, 2020 at 22:09