https://developer.mozilla.org/en-US/docs/Web/HTML/Element/da...
Really simple engineering.
Htmx sounds like a lovely idea, but doesn't it introduce a ton of latency compared to client-side operations?
Also, many autocompletes do a round trip anyway. The htmx version just returns the html already rendered, rather than, say, JSON that requires further processing and injecting.
Here are a couple of Go templates from a sample project that show it:
{{define "autoc_data" -}}
{{- range . -}}
<option>{{.}}</option>
{{- end -}}
{{- end}}
{{define "autoc" -}}
<input name="{{.Id}}" id="{{.Id}}" type="text" list="{{.Id}}_data"
hx-get="/autoc/{{.Id}}/search"
hx-trigger="keyup delay:300ms"
hx-target="#{{.Id}}_data">
<datalist id="{{.Id}}_data">
{{- template "autoc_data" -}}
</datalist>
{{- end}}
In response to `/autoc/<id>/search`, the server just responds with a list of strings matching the user's input, formatted with the `autoc_data` template. Htmx injects that into the `<datalist>` directly.My first thought is that frameworks like StimulusReflex / Hotwire can do something like that?
Also datalists appear quite different across different browsers, which is fine of course for a native form control, but annoying if you're aiming for a more consistent look.
I just wish that you could natively do something that works more like select elements, so users see the contents of the option elements but the value of the option element is actually what is populated in the form.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/op...
I can't say that this type of search has ever crossed my mind. This type of search would seem to me to be greatly ambiguous. For example, if you have "tomato" in the corpus then that obviously supercedes "margin-top" for the search string "mato". If you know the entire corpus, then I suppose you can take advantage of shortcuts like this when you know there is only one match, but then again it would seem to me that simply writing "margin-top" would require less mental gymnastics.
https://github.com/microsoft/vscode/blob/main/src/vs/base/co...
https://github.com/no-gravity/0g-typeahead
It is humming away nicely, doing hundreds of thousands of typeaheads each day across my websites.
I always think I should finally do the work and get rid of the jquery dependency. But so far, I just did not got around doing it.
Two pro tips:
1. Apparently this is also called “combo box” - Tailwind has one: https://tailwindui.com/components/application-ui/forms/combo...
I eventually rolled my own using tailwind’s scaffold: it ended up being about 300 lines of JS to handle things like keyboard actions, pressing enter, focus/non-focus, denounce search.
But the benefit? It does exactly what I want.
Your repo doesn't have a license.
https://github.com/no-gravity/0g-typeahead/blob/master/0g-ty...
The project is pretty much that one file. Twitter put the license there, so it did never cross my mind to remove it and put it into an extra file.
But it might make sense to put the whole repo (which is just the typeahead.js file plus a little demo) under that license to avoid confusion.
Disclaimer: I work on Typesense.
I tried building my own autocomplete thing for ablf.io and it was *tough*. The dataset was massive, over 400k canonical titles. And I wanted to split out different variants/localizations of the titles/authors so it's much more than that really. I ended up using the 'trie-search' npm package as that was really the only way get decent performance. I also did some hueristic levenstein distance stuff to order the results most optimally for the user. I found it helpful to add variants to the trie with vowels and common conjuctions like 'The' and 'A' removed – since people tend to forget those when searching for book titles (then when searching across the trie I can attempt different variants).
I guess the main learnings are: it's important to pay attention to the type of data you've got and how users will try to access it; don't assume they know titles of things nor the spelling. Use trie structures! Also: with large datasets it's beneficial to do upfront data prepartion to build variants. RAM is pretty cheap. Thinking... I imagine "AI semantic autocomplete" will be happening pretty soon which is exciting.
As soon as I started reading the docs on hx-sync and started imagining scenarios where that sort of functionality has been needed, I started thinking “man once the state gets this complex I’d really rather manage it in a proper programming language instead.”
I think it’s often reasonable to consider the DOM the “database” of the frontend, but it can also be nice to have an intermediary representation to create the appropriate transition. Inversion of control, you might say.
Might give you some ideas
This library does NOT send any keystrokes to Algolia, unless you configure it to use its services. This library is NOT coupled to Algolia's server, unless you explicitly configure it to.
And 1 nice thing is: You can add multiple sources to it, meaning you can search at the same time in various local and/or remote sources/servers and integrate all results into 1 result list with rich layout possibilities.
I also like very much to use the floating ui headless component
Example for an autocomplete/combo box https://codesandbox.io/s/fragrant-water-bsuirj?file=/src/App...
The fact that developers still put a "Send" button on most forms these days kind of amazes me. That makes me wonder. Am I wrong? When is it useful to have a "Go" or "Send" button, and demand that extra action from the user?
Maybe I'm not understanding your frustration...?
Are you saying that forms which are not submitted shouldn't have a separate submit button?
If so, I might agree, up to a point.
However any form that has to be submitted to a server absolutely MUST have a submit button, for the case when user input is complete and the user is still reviewing all the fields.
[0] https://bart.degoe.de/building-a-full-text-search-engine-150...