Skip to main content

ChoiceField

Struct ChoiceField 

Source
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>

Source

pub fn label(self, label: impl Into<String>) -> Self

Source

pub fn name(&self) -> &str

Source

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>

Source

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>

Source

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().

Source

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, and it cannot depend on another field.

Source

pub fn searchable(self) -> Self

Filters options as the user types, fetching from the relationship past the option cap.

Source

pub fn relationship<R>(self) -> Self
where 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.

Source

pub fn depends_on<M, T>( self, parent: &impl Watched<F>, column: impl Into<Path<M, T>>, ) -> Self
where M: Send + Sync + 'static, T: FormScalar + IntoExpr<T> + Send + Sync + 'static,

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.

Source

pub fn relationship_labelled<R>( self, label: impl Fn(&R::Model) -> String + Send + Sync + 'static, ) -> Self
where 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.

Trait Implementations§

Source§

impl<F> From<ChoiceField<F>> for Field

Source§

fn from(builder: ChoiceField<F>) -> Field

Converts to this type from the input type.
Source§

impl<F> IntoSchema<F> for ChoiceField<F>

Source§

impl<F> Watched<F> for ChoiceField<F>

Auto Trait Implementations§

§

impl<F = ()> !Freeze for ChoiceField<F>

§

impl<F = ()> !RefUnwindSafe for ChoiceField<F>

§

impl<F = ()> !UnwindSafe for ChoiceField<F>

§

impl<F> Send for ChoiceField<F>
where PhantomData<fn() -> F>: Send,

§

impl<F> Sync for ChoiceField<F>
where PhantomData<fn() -> F>: Sync,

§

impl<F> Unpin for ChoiceField<F>
where PhantomData<fn() -> F>: Unpin,

§

impl<F> UnsafeUnpin for ChoiceField<F>
where PhantomData<fn() -> F>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more