Can anyone suggest a simple solution for autosugge...
# cfml-beginners
e
Can anyone suggest a simple solution for autosuggest input. I'd like a user to enter data into a field and result to change with every char added.
a
every JS framework / tool created in the last 15yrs
Did you even google before asking?
Even
<cfinput>
does this (cringe). Don't use
<cfinput>
💯 3
e
Thanks and yes, I Googled it before
a
Right, so what did google suggest?
searching on your exact question as asked here has an article by CFML's very own Ben Nadel, above the fold. I reckon that's a CFML-friendly solution.
Although the server end of things is pretty irrelevant, so any of those options would probably be a good start
If I add "CFML" to the search string... a bunch of stuff from CFML community ppl.
e
Ok, I use Brave, not Chrome, so my results were different. Also, I tried to search again, but did not see Ben Nadel's solution anywhere in results.
p
Are you using a JS framework or are you happy with some jquery plugin? There are millions of jq versions
e
Well, this is why I asked for simple solution, preferably in CF (cfml) as I've never used JS nor Jquery before.
If, however jq solution is easy to understand, I would try it
a
jQuery is a bit old now, I think. But it's easy (and easier than wiring in a whole framework just for one autosuggest thing I don't think it's good to solve every problem with CFML... this is a client-side thing, so one should be using client-side technology to implement it. Also one really ought to be trying to learn new things. If you google "jquery autosuggest", there will be approximately one million good suggestions...
l
if it's a short set of options, you could try the HTML
datalist
tag which has
autocomplete
built in. You could populate that list via CFML on the back end and then you wouldn't need to use any javascript.
✅ 1
e
Thank you, datalist may work for me. Here is the example code I have, but it does not work. Query returns 1300 records - is this may be an issue?
<cfquery name="q0" datasource="#REQUEST.T#">
select distinct style_id
from styl_colo_identifier
where business_unit_id = '81'
and qr_style_ind = '1'
</cfquery>
<form action="" method="get">
<label for="style">Choose your style from the list:</label>
<input list="styles" name="style_id" id="styles">
<datalist id="styles">
<OPTION VALUE=""></OPTION>
<CFLOOP QUERY="q0">
<OPTION VALUE="#q0.style_id#">#q0.style_id#</OPTION>
</CFLOOP>
</datalist>
<input type="submit">
</form>
Fixed it! One more question: is it possible to modify it to start search on the first char typed?
e
Datalist does start the search based on the character attribute typed. This however is completely up to the browser. The first character is confirmed to work in all versions of Firefox & Chrome. You may experience lag if your data list is large, which comes back to maybe going back to ajax to do a CFC bind for your list of 1300 records.