#[non_exhaustive]pub struct FormField {}Expand description
One editable field: the column, its label, its field-type key (resolved through the field-type registry), typed options for that type, the validation rules it carries, and whether it holds translatable content. A serde descriptor, so it is authorable as data (later YAML) as well as by builder.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: String§label: TextThe field’s label, localized at render. Serde stays a plain string.
field_type: StringThe field-type registry key (text, textarea, or a plugin’s
vendor.name), resolved to behaviour at render time (see crate::field).
options: ValueThe keys that belong to the field’s type, as an object: in a file they are written on the field itself, beside its own. Null when there are none.
rules: Vec<Rule>Validation rules run on submit (see laterite_core::validation).
translatable: boolMarks a field whose value is translatable content. A reserved seam: the framework stores the value verbatim; a content-translation plugin reads the flag to manage per-locale values.
help: Option<Text>Help text shown beneath the control, localized at render.
enter: FieldEnterWhat Enter does in this field: submit (the form’s rule), off, or
next (moves to the next field).
span: SpanThe share of the row the field takes, on a twelve-column grid.
break_row: boolStarts a new row, whatever room the current one has left.
preset: Option<Preset>Follows another field as it is typed, until this one is edited.
Submitted but never shown: a plain hidden input carrying its value. The foreign key of a related record’s form is one.
trigger: Option<Trigger>Changes when another field’s state meets a condition.
Implementations§
Source§impl FormField
impl FormField
Sourcepub fn of(name: &str, label: impl Into<Text>, field_type: &str) -> Self
pub fn of(name: &str, label: impl Into<Text>, field_type: &str) -> Self
A field of a registered type by key.
Sourcepub fn preset(self, field: &str, shape: PresetShape) -> Self
pub fn preset(self, field: &str, shape: PresetShape) -> Self
Follows field as it is typed, shaped as shape, until this field is
edited.
Sourcepub fn trigger(self, trigger: Trigger) -> Self
pub fn trigger(self, trigger: Trigger) -> Self
Changes when trigger’s condition holds on the field it watches.
pub fn text(name: &str, label: impl Into<Text>) -> Self
pub fn textarea(name: &str, label: impl Into<Text>) -> Self
Sourcepub fn reference(name: &str, label: impl Into<Text>, source: &str) -> Self
pub fn reference(name: &str, label: impl Into<Text>, source: &str) -> Self
A reference field: a picker over a registered picker source (a vendor.name
key), which the field searches and resolves against. Builds the source
option so a descriptor needs no raw JSON.
Sourcepub fn select(
name: &str,
label: impl Into<Text>,
options: Vec<(&str, &str)>,
) -> Self
pub fn select( name: &str, label: impl Into<Text>, options: Vec<(&str, &str)>, ) -> Self
A dropdown over a fixed set of (value, label) choices.
Sourcepub fn radio(
name: &str,
label: impl Into<Text>,
options: Vec<(&str, &str)>,
) -> Self
pub fn radio( name: &str, label: impl Into<Text>, options: Vec<(&str, &str)>, ) -> Self
The same choices rendered as radio buttons.
Sourcepub fn password(name: &str, label: impl Into<Text>) -> Self
pub fn password(name: &str, label: impl Into<Text>) -> Self
A password: hashed on save, never rendered back, and left alone when the field is submitted blank on an edit.
Sourcepub fn repeater(
name: &str,
label: impl Into<Text>,
fields: Vec<FormField>,
) -> Self
pub fn repeater( name: &str, label: impl Into<Text>, fields: Vec<FormField>, ) -> Self
A list of rows, each holding fields, stored as an array of objects.
Sourcepub fn repeater_list(
name: &str,
label: impl Into<Text>,
fields: Vec<FormField>,
summary_field: Option<&str>,
) -> Self
pub fn repeater_list( name: &str, label: impl Into<Text>, fields: Vec<FormField>, summary_field: Option<&str>, ) -> Self
A repeater whose rows collapse to the line that names them, opening one
at a time. summary_field names the sub-field that titles a row; unset,
the first one does.
Use it when a row holds more than one or two fields: rendered inline those become columns, and a row of four is already unreadable. A single narrow column is better left inline, where collapsing would hide the one thing worth seeing.
Sourcepub fn options(self, options: Value) -> Self
pub fn options(self, options: Value) -> Self
Sets the field type’s typed options (the type validates them at render).
Sourcepub fn required_on(self, mode: Mode) -> Self
pub fn required_on(self, mode: Mode) -> Self
Requires a non-empty value in one mode only (for example a password set on create but left unchanged on edit).
Sourcepub fn unique(self) -> Self
pub fn unique(self) -> Self
Requires the value to be unique in this field’s column (a DB probe that ignores the edited row on update).
Sourcepub fn max_length(self, n: usize) -> Self
pub fn max_length(self, n: usize) -> Self
Caps the value’s length.
Sourcepub fn min_length(self, n: usize) -> Self
pub fn min_length(self, n: usize) -> Self
Requires at least n characters when the value is non-empty.
Sourcepub fn translatable(self) -> Self
pub fn translatable(self) -> Self
Marks this field as translatable content (see FormField::translatable).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for FormField
impl<'de> Deserialize<'de> for FormField
Source§fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
Auto Trait Implementations§
impl Freeze for FormField
impl RefUnwindSafe for FormField
impl Send for FormField
impl Sync for FormField
impl Unpin for FormField
impl UnsafeUnpin for FormField
impl UnwindSafe for FormField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more