pub struct ChoiceField<F = ()>(/* private fields */);Expand description
A choice field: Field::choice, or a record form’s choice control (F is the form).
Implementations§
Source§impl<F> ChoiceField<F>
impl<F> ChoiceField<F>
Sourcepub fn default(self, value: impl IntoFormValue) -> Self
pub fn default(self, value: impl IntoFormValue) -> Self
Fills the create form’s control with value: any FormScalar or a &str in
the form spelling, or, for a multiple choice, an array
or Vec of them. On a disabled field it is the value a create
stores. A schema refuses a default the control never posts: one a typed field
does not parse, one not among a choice’s options, a list on a control posting one
value, and one value on a multiple choice.
Field::choice(Post::fields().status())
.options(["draft", "published"])
.default("draft");
Field::text(Post::fields().views()).default(0_i64).disabled();
Field::choice_input("channels")
.options(["email", "sms"])
.multiple()
.default(["email"]);Source§impl<F> ChoiceField<F>
impl<F> ChoiceField<F>
pub fn label(self, label: impl Into<String>) -> Self
pub fn name(&self) -> &str
Sourcepub fn visible_when(
self,
watched: &impl Watched<F>,
values: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn visible_when( self, watched: &impl Watched<F>, values: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Shows the field only while watched posts one of values: an option’s value, or
true for a checked toggle. A hidden field posts nothing, so an edit keeps its
stored value and a create takes its blank answer; a field with no blank answer
cannot be conditional.
let kind = Field::choice(Customer::fields().kind()).options(["person", "company"]);
let vat = Field::text(Customer::fields().vat_number()).visible_when(&kind, ["company"]);
Schema::new((kind, vat));Source§impl<F> ChoiceField<F>
impl<F> ChoiceField<F>
Sourcepub fn help(self, text: impl Into<String>) -> Self
pub fn help(self, text: impl Into<String>) -> Self
Renders text under the control, which the control names as its description.
Sourcepub fn disabled(self) -> Self
pub fn disabled(self) -> Self
Renders the control disabled on the create and edit forms. The server drops a
value posted for it anyway, so an edit keeps the stored value and a create takes
the field’s default, else its blank answer; a field with neither cannot be
created, and its panel refuses to mount.
Sourcepub fn disabled_on_edit(self) -> Self
pub fn disabled_on_edit(self) -> Self
Renders the control disabled on the edit form only: the create form sets the value, and no edit changes it.
Sourcepub fn custom(self, control: impl Control + 'static) -> CustomField<F>
pub fn custom(self, control: impl Control + 'static) -> CustomField<F>
Renders the field with an app’s Control instead, as Field::custom does:
how a record form’s control takes a custom input. The field keeps its key and
label; the replaced control’s own modifiers, such as email, unique or
options, are dropped with it.
Source§impl<F> ChoiceField<F>
impl<F> ChoiceField<F>
Sourcepub fn options(self, options: impl IntoOptions) -> Self
pub fn options(self, options: impl IntoOptions) -> Self
Static options: values that are their own label
(["draft", "published"]), (value, label) pairs, or a
#[derive(Options)] enum’s
options().
Sourcepub fn multiple(self) -> Self
pub fn multiple(self) -> Self
Takes several options: a checkbox per option, posting the field’s key once per checked
box. A record form’s many-to-many field (Vec<K> with #[form(relationship = R)]) is one;
parse_list reads one in an action’s input.
It offers at most MAX_RELATIONSHIP_OPTIONS
records: past them it lists none but the chosen ones, and refuses a submission choosing
another. A record form’s edit re-checks only the keys the record does not link yet.
searchable filters the listed options as the user types. A condition cannot watch it,
it cannot depend on another field, and its default is a list.
Sourcepub fn searchable(self) -> Self
pub fn searchable(self) -> Self
Filters options as the user types, fetching from the relationship past the option cap.
Sourcepub fn relationship<R>(self) -> Selfwhere
R: OptionSource + 'static,
pub fn relationship<R>(self) -> Selfwhere
R: OptionSource + 'static,
Loads options from a related source’s tenant-scoped query, each valued by its primary key
and labelled by the source’s label, degrading to type-to-search
past the option cap.
A resource’s options carry its record_title, the
title its detail page shows. relationship_labelled
labels one field’s options otherwise.
Sourcepub fn depends_on<M, T>(
self,
parent: &impl Watched<F>,
column: impl Into<Path<M, T>>,
) -> Self
pub fn depends_on<M, T>( self, parent: &impl Watched<F>, column: impl Into<Path<M, T>>, ) -> Self
Offers only the related rows whose column column equals the value parent posts: the
cities of the chosen country. The browser fetches the options again when parent changes,
and a submission must name a row of the posted parent value. A blank parent offers none.
column belongs to the relationship’s source model; mounting
refuses another model, a choice without a relationship, and a parent the schema does not
place.
Sourcepub fn relationship_labelled<R>(
self,
label: impl Fn(&R::Model) -> String + Send + Sync + 'static,
) -> Selfwhere
R: OptionSource + 'static,
pub fn relationship_labelled<R>(
self,
label: impl Fn(&R::Model) -> String + Send + Sync + 'static,
) -> Selfwhere
R: OptionSource + 'static,
Loads options as relationship does, labelling each by label
instead of the source’s label: to tell apart records that share a title. The option’s
record loads without its relations.