7 ms·
Well, they "wait" for a fraction of a second maybe. And you put it behind a typing delay so it responds only when the user is ready. Also, many autocompletes d
by kitd 3y ago
Well, they "wait" for a fraction of a second maybe. And you put it behind a typing delay so it responds only when the user is ready.
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.