Skip to content

Type-to-filter dropdowns for the aliquot and sample forms (part of #209) - #212

Merged
olsonjp merged 1 commit into
mainfrom
combobox-type-to-filter
Nov 11, 2026
Merged

olsonjp merged 1 commit into
mainfrom
combobox-type-to-filter

Conversation

@olsonjp

@olsonjp olsonjp commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Part of #209. This PR does not close it: the Storage and Consumables forms and the box page's assign list are still to do (see "Not in this PR").

The problem

The Parent aliquot dropdown rendered one <option> per aliquot (about 10,700 in the lab's data), so the form was slow to load and the right aliquot was impossible to find by scrolling. Sample and the other dropdowns could only be scrolled too.

What it does

  • A type-to-filter control replaces dropdowns that have many options. A text box with a list under it; type to narrow it, then pick with the mouse, or Down, Up and Enter. A x button clears the choice. It follows the ARIA combobox pattern (a combobox text box, a listbox, announced result counts).
  • Parent aliquot is searched on the server. The select renders only its blank and current choice. Typing calls a new JSON endpoint, /samples/aliquot-options/?q=..., which returns at most 20 matches and says when there are more (the list then shows "Keep typing to narrow the results"). The page no longer carries thousands of options, and the number of queries does not depend on how many aliquots exist (both are tested).
  • Matching in the picker: every word typed must match the sample name, type or passage, so hela p8 finds the p8 aliquots of HeLa. A word that is a number, with or without a leading #, also matches the aliquot number, and an aliquot with exactly that number is listed first. Soft-deleted aliquots are not offered.
  • Labels tell similar aliquots apart: HeLa #1234 · Cells · p8 · 2026-03-05 (missing parts are left out).
  • The other dropdowns filter the options already on the page: Sample, Box and Lab member on the aliquot form, Source on the sample form, and Box on the move-aliquot form. Both create and edit forms get it. Lists with fewer than 8 options stay plain selects, so the 3 types and few dispositions are unchanged; a list gets the control once it grows.

How it is built

  • Vanilla JavaScript in static/krill/js/combobox.js (about 300 lines), loaded by the base layout, in the same style as the app's other scripts. No new dependency, no build step.
  • It is a progressive enhancement over the form's own <select>, which stays in the page (visually hidden) and holds the value. Django's fields, validation, prefilled values, form submission and "Create child aliquot" are unchanged; the create page's script that clears the Box field now also notifies the control.
  • If setting a field up ever fails, the plain <select> is put back so a field never disappears.
  • Server side: sample/widgets.py (RemoteSelect, aliquot_choice_label, mark_comboboxes), the aliquot_options view, and data- attributes on the form widgets. Validation of Parent aliquot still uses the full queryset, so any existing aliquot that is posted is accepted and an unknown id is refused.

Decisions to check

  • Without JavaScript, the Parent aliquot field keeps its current value but a new one cannot be chosen; the other dropdowns fall back to plain selects. The app already relies on JavaScript elsewhere.
  • Access levels: nothing else in the app filters aliquots by access level, and the Aliquots list shows all of them, so the endpoint does the same.
  • Parent aliquot can be any non-deleted aliquot, whatever its disposition.

Not in this PR (still open in #209)

Storage forms (site, device, shelf, rack, box), Consumables forms, and the box detail page's "assign aliquot" list, which also overlaps #207.

Verification

  • sample/tests/test_combobox.py (28 tests): the endpoint (login required, blank query, case, passage and type, words combined, number with and without #, exact number first, the 20-result limit and the more flag, deleted excluded, ordering, constant query count); the widget and forms (only a blank option is rendered, a chosen or current parent shows with its label, valid and unknown posted ids, no growth in queries as aliquots are added, which dropdowns are marked); and the pages (the prefilled create-child page ships one option instead of many, the layout loads the script). Full suite: 765 tests, OK. No migrations.
  • The script parses (checked with macOS's JavaScript engine; Node is not installed here).
  • Not verified: the control's behaviour. There is no JavaScript test runner, and I cannot see a browser, so nothing automated exercises opening, filtering, choosing, the keyboard, or dark mode.

Manual checklist for review

  • Create aliquot: type in Parent aliquot (try hela, p8, #123, a number) and pick a result; the form submits and the child has that parent.
  • Create child aliquot from an aliquot opens with the parent already shown; creating works.
  • Keyboard: Down and Up move, Enter chooses without submitting the form, Esc closes, Tab leaves the field and drops text that was not chosen.
  • The x clears the choice. Unticking Assign to storage box also clears the box field.
  • Leaving a required dropdown empty and submitting shows the browser's message near it.
  • Sample and Box filter as you type; a short list such as Type stays a plain select.
  • Edit an existing aliquot and sample: current values are shown and can be changed.
  • Dark mode, and a narrow window.

🤖 Generated with Claude Code

Part of #209.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@olsonjp
olsonjp merged commit fa0bcd3 into main Nov 11, 2026
1 check passed
@olsonjp
olsonjp deleted the combobox-type-to-filter branch November 11, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant