Multi-Field Autocomplete

I followed the tutorial for autocomplete and it’s a wonderful feature.

My question though is can you set more than one field as the text and the value? For example, my database table has a field for first name and one for last name. I’d like the user to start typing the first name and bring up a suggested list containing both first and last name and use that for the submitted value.

Possible?

How about concatenating your first name and last name using a custom query?

Something like this:

SELECT CONCAT(`first_name`, ' ', `last_name`) as full_name FROM `users`;
1 Like

Thanks Ken,

That is a very interesting concept. In theory that would also allow the user to start typing in the last name as well.

Guess I have my weekend project planned now. :wink:

1 Like

An even better option: Concat multiple fields in the TEXT property of the select itself. That way you don’t need to write a custom query.

From the docs:

The TEXT property is set to country_name.
You can set it to say show the capital at the same time like so:
country_name + ' - ' + country_capital

The demarcation is just for better readability (and how I have always used this).
country_name country_capital should work too.

3 Likes

Yep, that would also work, and be faster to implement!

I tend to put as much code as possible on the server side so I can reuse the backend for different front ends (webapp, mobile app, etc.) and limit the processing done on client devices which have less horsepower. One concat on the client is obviously no big deal, but I’ve run into issues when there is lots of formatting, or calcs to be done on a page, so I just push to server as my default.

Great to have options.

True. Thats is the better approach when reusability is required.

One of the best features of Wappler… lots of ways to do the same thing. Sometimes a curse, as it adds to confusion. :sweat_smile:

Thanks @mebeingken , I went with your solution as I can see reusing it a few times in my dashboard. Works wonderfully!

We have designed the Autocomplete to work indeed with any App Connect dynamic expression as “Text Field” and “Value Field”

So you can enter any preformatted (with Data Formatter) expression as text and store the associated id of choice

2 Likes