Moey Icons
No results. Try “dialog”, “dark” or “grid”.
Forms

Combobox

A text field with suggestions. Point any input at a <datalist> and it gets a Moey suggestion list instead of the browser's — typing filters it, best matches first, accents and capitals don't matter. Suggestions can also come from your server.

<label class="form-label" for="city">City</label>
<input class="form-control" id="city" name="city" list="cities">
<datalist id="cities">
  <option value="Lisbon" data-moey-detail="Portugal">
  <option value="Porto" data-moey-detail="Portugal">
  <option value="São Paulo" data-moey-detail="Brazil">
  …
</datalist>
  • Keys: ↓ / ↑ open the list and move, Enter picks, Esc closes it (press again to clear the field). Clicking the field shows everything.
  • Anything can be typed — the list only suggests. Use data-moey-strict to allow only listed values.
  • Without JavaScript it's still a normal input with the browser's own suggestions.

Only values from the list

data-moey-strict: the first match is highlighted so Enter takes it, capitals are corrected ("ana kim" → "Ana Kim"), and anything else makes the field invalid. data-moey-id-field also fills a hidden input with the item's data-moey-id — so people pick a name and your form sends the id.

Pick someone from the team.
<input class="form-control" id="assignee" list="team" data-moey-strict data-moey-id-field="#assignee-id" required>
<input type="hidden" name="assignee_id" id="assignee-id">
<datalist id="team">
  <option value="Ana Kim" data-moey-detail="Design" data-moey-color="pink" data-moey-id="u-101">
  <option value="Max Ruiz" data-moey-detail="Support" data-moey-color="cyan" data-moey-id="u-102">
  …
</datalist>

Add new values

data-moey-create offers "Add “…”" when nothing matches. It fires moey:create (cancel it to say no, or save it to your server) and adds the value to the list.

<input class="form-control" list="categories" data-moey-create>
<datalist id="categories">
  <option value="Mugs" data-moey-group="Kitchen">
  <option value="Totes" data-moey-group="Bags">
  …
</datalist>

<script>
  input.addEventListener('moey:create', (e) => {
    saveCategory(e.detail.value);           // or e.preventDefault() to refuse
  });
</script>

From your server

data-moey-source fetches suggestions as people type ({q} is replaced with what's typed). Return a JSON array of strings, or of { value, label, detail, icon, group, id }. Requests wait until typing pauses, old ones are cancelled, and answers are remembered. Or pass a function from code.

Loaded by a function (with a fake half-second delay).
<input class="form-control" data-moey-source="/api/countries?q={q}">

<input class="form-control" id="customer" type="search">
<script>
  Moey.combobox('#customer', {
    source: async (query, signal) => {
      const res = await fetch('/api/customers?search=' + encodeURIComponent(query), { signal });
      const people = await res.json();
      return people.map((p) => ({ value: p.name, detail: p.email, id: p.id }));
    },
  });
</script>

Floating labels, input groups and tag inputs

It's still a normal input, so it works everywhere one does — including a tag input, where picking a suggestion adds a tag.

<div class="form-floating">
  <input class="form-control" id="ship-city" list="cities">
  <label for="ship-city">Ship to city</label>
</div>
<input class="form-control" list="skills" data-moey-tags>

From code

const c = Moey.combobox('#city', { strict: true, create: false, source: async (q) => [...] });
c.open(); c.close();
c.value = 'Porto';
c.refresh();                                   // forget remembered server answers

input.addEventListener('moey:pick', (e) => e.detail.item);     // { value, label, detail, id, … }
AttributeWhat it does
list="id" + <datalist>The suggestions. Options can have data-moey-detail, -icon, -color, -group, -id, -keywords (extra words to match)
data-moey-source="/api?q={q}"Suggestions from your server instead (JSON)
data-moey-strictOnly values from the list
data-moey-createOffer "Add “…”" for new values (event moey:create)
data-moey-id-field="#id"Also fill a hidden input with the picked item's id
data-moey-min-chars · data-moey-limit · data-moey-delayLetters before suggesting (server: 1) · most shown (50) · wait after typing (200 ms)
data-moey-nativeKeep the browser's own suggestions