A field that follows or watches one the form does not have stops the boot,
naming it. An action or condition the page does not know is refused when the
file is read.
use laterite_admin::options::{OptionCx, OptionEntry, OptionError, OptionSource, OptionSourceReg};
struct States;
#[async_trait]
impl OptionSource for States {
async fn options(&self, db: &Db, cx: &OptionCx<'_>) -> Result<Vec<OptionEntry>, OptionError> {
let country = cx.values.get("country").map(String::as_str).unwrap_or("");
Ok(states_of(db, country)
.await?
.into_iter()
.map(|s| OptionEntry::new(s.code, s.name))
.collect())
}
}
registry.add_option_source(OptionSourceReg::new("acme.states", Arc::new(States)));
registry.add_option_source(OptionSourceReg::fixed(
"acme.sizes",
vec![OptionEntry::new("s", "Small"), OptionEntry::new("l", "Large").note("From 40 cm")],
));
Key
Value
options
On a select, radio or checklist: the name of a registered source, in place of a list.
depends_on
A field, or a list of fields. When one changes, this field is drawn again and its source is asked with the form’s current values.
OptionCx
Holds
field
The field’s name.
value
The field’s current value.
values
Every value the form holds, by field name. For a list filter: every filter value, by filter name.
id
The record being edited, on an edit page.
i18n
The request’s translator.
OptionEntry
Effect
::new(value, label)
A choice storing value, shown as label.
.note(text)
A second line under the label (radio, checklist).
.disabled()
Shown and not selectable (select, radio).
.group(heading)
Sits under heading (select, checklist).
Built-in source
Offers
laterite.timezones
Every timezone name.
laterite.locales
The languages the admin is translated into.
A source name nobody registered, a field depending on one the form does not
have, and a field depending on itself stop the boot. A row of a repeater
lists its options in place.