Skip to main content

Field

Struct Field 

Source
pub struct Field { /* private fields */ }
Expand description

One form field binding a lens to the control editing it, offering only that control’s modifiers so a modifier on the wrong control does not compile.

Field::text(lens!(User.name)).placeholder("Ada Lovelace"); // TextField
Field::text(lens!(User.email)).email().unique();
Field::text(lens!(User.age)); // typed: an `i64` column
Field::text(lens!(Post.body)).multiline(6);
Field::choice(lens!(Post.status)).options(Status::options()); // ChoiceField
Field::choice(lens!(Post.author_id)).relationship::<AuthorResource>();
Field::file(lens!(Doc.path)); // FileField
Field::toggle(lens!(Post.featured)); // CustomField

Options belong to a choice: a text field has no options method.

Implementations§

Source§

impl Field

Source

pub fn text<M, T>(lens: impl Into<Path<M, T>>) -> TextField
where M: Model, T: FormScalar + IntoExpr<T> + 'static,

Binds any FormScalar column, storing the type’s own spelling and probing uniqueness through the lens.

Source

pub fn choice<M, T>(lens: impl Into<Path<M, T>>) -> ChoiceField
where M: Model,

A choice field over any column, with options from options or relationship.

Source

pub fn file<M>(lens: impl Into<Path<M, String>>) -> FileField
where M: Model,

A file field over a String column holding the uploaded path, rendering no value attribute.

Source

pub fn toggle<M>(lens: impl Into<Path<M, bool>>) -> CustomField
where M: Model,

A checkbox over a bool column that submits false when unchecked.

Source

pub fn custom<M, T>( lens: impl Into<Path<M, T>>, control: impl Control + 'static, ) -> CustomField
where M: Model, T: FormScalar,

A field over any FormScalar column, rendered by an app’s Control.

Source

pub fn repeater<M, T>(lens: impl Into<Path<M, List<T>>>) -> RepeaterField
where M: Model, T: RepeaterItem,

A row of T’s controls per item of a #[document] list of T, which the browser adds, removes and moves: a record form’s #[form(repeat)] control.

Each row posts its item’s keys under {key}.{row}.. A resource’s form and an action’s input read them into key’s rows, and a page handling its own post reads it with Schema::read; the items then parse with parse_items.

Source

pub fn text_input<T: FormScalar>(name: impl Into<String>) -> TextField

A text field posting name, a key no column binds: an ActionInput field. T picks the input type, as a column’s type does for Field::text.

Source

pub fn choice_input(name: impl Into<String>) -> ChoiceField

A choice field posting name, a key no column binds, with options from options.

Source

pub fn toggle_input(name: impl Into<String>) -> CustomField

A checkbox posting name, a key no column binds, that submits false when unchecked.

Source

pub fn name(&self) -> &str

The key the field posts: the storage column its path names.

Trait Implementations§

Source§

impl Debug for Field

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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> From<CustomField<F>> for Field

Source§

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

Converts to this type from the input type.
Source§

impl<F> From<FileField<F>> for Field

Source§

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

Converts to this type from the input type.
Source§

impl<F> From<RepeaterField<F>> for Field

Source§

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

Converts to this type from the input type.
Source§

impl<F> From<TextField<F>> for Field

Source§

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

Converts to this type from the input type.
Source§

impl IntoSchema for Field

Auto Trait Implementations§

§

impl !Freeze for Field

§

impl !RefUnwindSafe for Field

§

impl !UnwindSafe for Field

§

impl Send for Field

§

impl Sync for Field

§

impl Unpin for Field

§

impl UnsafeUnpin for Field

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