Skip to main content

RepeaterField

Struct RepeaterField 

Source
pub struct RepeaterField<F = ()>(/* private fields */);
Expand description

A repeater: Field::repeater, or a record form’s #[form(repeat)] control (F is the form).

  • Each row posts its item’s fields under its own prefix (steps.0.minutes), and the repeater’s own key lists the rows in the order they show. A refused row renders its error under its own control, and the rows come back in the order the user left them.
  • A repeater takes at most MAX_REPEATER_ROWS (100) rows; a submission listing more is refused.
  • No rows is the repeater’s blank answer, so a repeater is never required. An edit that does not post the repeater, such as one hidden by a condition, keeps the stored rows; one that posts no rows stores an empty list.
  • Adding, removing and moving rows needs JavaScript. Without it the stored rows still edit.
  • An action’s input can place a repeater too, with a hand-written FormInput whose parse reads the rows with parse_items.
  • On the detail page, RepeaterColumn shows each item’s fields under their labels. The model’s default detail page includes one; its table does not.
  • Not supported inside an item: an embedded value, another repeater, a relationship, a file field and a condition.

Implementations§

Source§

impl<F> RepeaterField<F>

Source

pub fn label(self, label: impl Into<Text>) -> 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. A field shows under one condition: a later call replaces an earlier one, so a field depending on two watched fields sits in a Section guarded by the other.

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));
  • The browser shows and hides the field as the watched one changes, with no request. A hidden field’s control is disabled, so the browser neither validates nor posts it. Without JavaScript, the fields start as the stored values show them and stay that way.
  • The panel reads a submission the same way and drops a hidden field’s posted key, and a file field’s carried upload: an edit keeps the stored value, and a create stores the blank answer. A conditional field therefore needs a blank answer, and mounting refuses one without.
  • Mounting also refuses a value the watched field never posts (a choice’s option or a toggle’s true and false are checked), and a condition watching a field that another condition hides while the guarded field still shows: place the guarded field inside the block that hides the watched one. A schema also refuses a condition watching a field it does not place, which only a page’s or an action’s schema can do: a resource’s form places every record-form field.
  • A toggle is followed through its checkbox. An app’s own checkbox Control posts the same value checked or not, so a condition cannot follow it.
  • A multiple choice’s key holds a list, which no condition value spells: mounting refuses a condition watching one.
Source

pub fn span(self, columns: u8) -> Self

Spans columns of the Grid holding the field, clamped to 1..12. While the grid stacks its children, or lays out fewer columns, the field spans them all. Outside a grid, the span does nothing.

Source

pub fn span_full(self) -> Self

Spans every column of the Grid holding the field.

Source§

impl<F> RepeaterField<F>

Source

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

The add button’s label, over “Add item”.

Source

pub fn min_items(self, count: usize) -> Self

Refuse a submission of fewer than count rows, and disable each row’s Remove button while the list holds no more. A minimum above max_items fails the mount.

Source

pub fn max_items(self, count: usize) -> Self

Refuse a submission of more than count rows, and disable the add button while the list holds that many. A count above MAX_REPEATER_ROWS, which every repeater keeps to, fails the mount.

Trait Implementations§

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> IntoSchema<F> for RepeaterField<F>

Auto Trait Implementations§

§

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

§

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

§

impl<F> Forget for RepeaterField<F>

§

impl<F> Freeze for RepeaterField<F>
where PhantomData<fn() -> F>: Freeze,

§

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

§

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

§

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

§

impl<F> UnsafeUnpin for RepeaterField<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> ErasedDestructor for T
where T: 'static,

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