Skip to content
Sections
Fiesta

field-select

Choices and actions The controls that pick from options, and the rows that end a form. Each one sits in a padded rst-box, because that is the card a form goes in.

The field envelope around a native select. Add data-rst-select and select.js turns it into a filterable combobox; the native select is still what the form submits. Worth it from about ten options.

Each example is live, but its links go nowhere. HTML shows the markup to copy.

Three options: a native select

Preview

Put this inside <section rst-box><form rst-form>.

<div rst-field>
  <label rst-field-label for="sel_few">Role</label>
  <select rst-input id="sel_few" name="sel_few">
    <option value="admin" selected>Admin</option>
    <option value="editor">Editor</option>
    <option value="member">Member</option>
  </select>
</div>

Twelve options: the filterable combobox

Add data-rst-select from about ten options. Below that, leave it off: search over a handful of items is furniture, not help.

Preview

Put this inside <section rst-box><form rst-form>.

<div rst-field>
  <label rst-field-label for="sel_many">City</label>
  <select rst-input id="sel_many" name="sel_many" data-rst-select data-rst-select-filter="Type to filter" data-rst-select-results="{n} results" data-rst-select-result-one="1 result" data-rst-select-no-matches="No matches" aria-describedby="sel_many-help">
    <option value="dublin" selected>Dublin</option>
    <option value="lisbon">Lisbon</option>
    <option value="madrid">Madrid</option>
    <option value="berlin">Berlin</option>
    <option value="rome">Rome</option>
    <option value="athens">Athens</option>
    <option value="helsinki">Helsinki</option>
    <option value="reykjavík">Reykjavík</option>
    <option value="warsaw">Warsaw</option>
    <option value="zagreb">Zagreb</option>
    <option value="tallinn">Tallinn</option>
    <option value="valletta">Valletta</option>
  </select>
  <p rst-field-help id="sel_many-help">Start typing to filter.</p>
</div>

Twelve options, Plain: the enhancement opted out

Preview

Put this inside <section rst-box><form rst-form>.

<div rst-field>
  <label rst-field-label for="sel_plain">City</label>
  <select rst-input id="sel_plain" name="sel_plain">
    <option value="dublin" selected>Dublin</option>
    <option value="lisbon">Lisbon</option>
    <option value="madrid">Madrid</option>
    <option value="berlin">Berlin</option>
    <option value="rome">Rome</option>
    <option value="athens">Athens</option>
    <option value="helsinki">Helsinki</option>
    <option value="reykjavík">Reykjavík</option>
    <option value="warsaw">Warsaw</option>
    <option value="zagreb">Zagreb</option>
    <option value="tallinn">Tallinn</option>
    <option value="valletta">Valletta</option>
  </select>
</div>

Required, with an error

Preview

Put this inside <section rst-box><form rst-form>.

<div rst-field>
  <label rst-field-label for="sel_error">Role</label>
  <select rst-input id="sel_error" name="sel_error" required aria-invalid="true" aria-describedby="sel_error-error">
    <option value="admin" selected>Admin</option>
    <option value="editor">Editor</option>
    <option value="member">Member</option>
  </select>
  <p rst-field-error id="sel_error-error" role="alert">Pick a role for this person.</p>
</div>

Hand-written, with optgroups

Grouped choices are optgroups you write yourself. select.js keeps the groups rather than dropping them; a select can also refuse the enhancement outright with data-rst-select="false".

Preview

Put this inside <section rst-box><form rst-form>.

<div rst-field>
  <label rst-field-label for="sel_grouped">Region</label>
  <select rst-input id="sel_grouped" name="sel_grouped" data-rst-select data-rst-select-filter="Type to filter" data-rst-select-results="{n} results" data-rst-select-result-one="1 result" data-rst-select-no-matches="No matches">
    <optgroup label="Europe">
      <option value="dublin" selected>Dublin</option>
      <option value="lisbon">Lisbon</option>
      <option value="warsaw">Warsaw</option>
    </optgroup>
    <optgroup label="Americas">
      <option value="montreal">Montréal</option>
      <option value="lima">Lima</option>
      <option value="austin">Austin</option>
    </optgroup>
    <optgroup label="Asia">
      <option value="osaka">Osaka</option>
      <option value="hanoi">Hanoi</option>
      <option value="dhaka">Dhaka</option>
    </optgroup>
    <optgroup label="Africa">
      <option value="accra">Accra</option>
      <option value="nairobi">Nairobi</option>
      <option value="tunis">Tunis</option>
    </optgroup>
  </select>
</div>