Expand description
Generic chooser registry — register a chooser for any
#[derive(Model)] type, generalising the three hand-rolled choosers
(page / snippet / document).
A host registers with
register_chooser!(Ty, "slug", "Label", "title_field", "sub_field");
the admin then serves /cms-admin/__chooser/<slug>?q=… returning the
same { "items": [ { id, title, sub, … } ] } shape the bespoke
choosers use. The editor’s chooser overlay (cms-ux.js) resolves an
unregistered data-chooser-kind to this endpoint automatically, so a
registered chooser needs no JavaScript change — a widget just
sets its slug as the kind.
Search runs over the model’s admin(search_fields = …) (the same
metadata the framework admin uses), matched case-insensitively as a
substring on each declared field — mirroring the in-memory filter the
bespoke choosers already do. A dedicated form WidgetKind for model
choosers is the natural next step.
Structs§
- Chooser
View Set - One registered chooser.
Constants§
- CHOOSER_
LIMIT - Cap on returned rows — matches the bespoke choosers’ limit.
Functions§
- filter_
and_ normalize - Filter already-serialized
rowsbyquery(case-insensitive substring oversearch_fields), cap atlimit, and normalise each to carry atitle+subkey (fromtitle_field/sub_field) alongside its original fields. An empty / blank query returns the firstlimitrows. Pure — theregister_chooser!thunk and the unit tests both call it. - find
- The chooser registered under
slug, if any. - registered
- Every registered chooser, sorted by slug.
Type Aliases§
- Search
Rows Fn - Type-erased “search rows as normalised chooser items”. Built by
register_chooser!from the concrete model’sobjects().fetch()+ its schemasearch_fields(the fetch is a derive-generated inherent method, so it can’t be reached generically — hence the thunk, same shape ascrate::admin::model_admin).