https://developer.mozilla.org/en-US/docs/Web/HTML/Element/da...
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.As mentioned, many (most even?) autocompletes do it on the fly, and probably without you realising.
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...