#[non_exhaustive]pub struct Field { /* private fields */ }Expand description
One field of a resource’s form: its name (the form’s and the model’s
field), its label, its kind and how it looks. The rules are the form
type’s own (Validate); required here only marks the
field for people and the browser.
use renox_admin::Field;
let fields = vec![
Field::text("name", "Name").required(),
Field::select("status", "Status", [("draft", "Draft"), ("live", "Live")]).required(),
Field::money("price", "Price").required(),
Field::belongs_to("category_id", "Category", "categories", "name"),
Field::textarea("notes", "Notes").span_full(),
Field::toggle("active", "Active").default_value(true),
];Implementations§
Source§impl Field
impl Field
Sourcepub fn password(name: &str, label: &str) -> Self
pub fn password(name: &str, label: &str) -> Self
A password. The edit page leaves it empty: make the form’s field an
Option<String> and change the password only when one was typed.
Sourcepub fn textarea(name: &str, label: &str) -> Self
pub fn textarea(name: &str, label: &str) -> Self
Several lines of text (rows(n), 4 by default).
Sourcepub fn money(name: &str, label: &str) -> Self
pub fn money(name: &str, label: &str) -> Self
An amount the model keeps in the smallest unit (cents, like the
data grid’s money columns), with APP_CURRENCY’s code before it.
The form shows and takes whole units: with USD, 1299 shows as
12.99 (a 0.01 step), and 12.99 is read back as 1299 before
the form’s rules and fill see it
(rounded to the cent). A currency without decimals (IDR, JPY) is
as typed. Rules on the form (min, max) are in the smallest unit.
Sourcepub fn date(name: &str, label: &str) -> Self
pub fn date(name: &str, label: &str) -> Self
A date with the kit’s calendar, sent as YYYY-MM-DD (a NaiveDate).
Sourcepub fn datetime(name: &str, label: &str) -> Self
pub fn datetime(name: &str, label: &str) -> Self
A date and a time, sent as YYYY-MM-DDTHH:MM (a NaiveDateTime in
the form; Renox adds the seconds). The edit page shows the stored
moment’s first 16 characters, so store UTC or a naive time.
Sourcepub fn select<V: Into<String>, L: Into<String>>(
name: &str,
label: &str,
options: impl IntoIterator<Item = (V, L)>,
) -> Self
pub fn select<V: Into<String>, L: Into<String>>( name: &str, label: &str, options: impl IntoIterator<Item = (V, L)>, ) -> Self
One of options, (value, label) pairs. searchable() adds a box
that filters them.
Sourcepub fn checkbox(name: &str, label: &str) -> Self
pub fn checkbox(name: &str, label: &str) -> Self
A checkbox: a bool in the form (ticked or not).
Sourcepub fn toggle(name: &str, label: &str) -> Self
pub fn toggle(name: &str, label: &str) -> Self
A switch: a bool in the form, for a setting that is on or off.
Sourcepub fn belongs_to(name: &str, label: &str, table: &str, title: &str) -> Self
pub fn belongs_to(name: &str, label: &str, table: &str, title: &str) -> Self
The id of a row of table, chosen by its title column: a
searchable select of table’s rows (the first 1,000, by title).
Pair it with #[validate(exists("table", "id"))] on the form.
table and title may only have letters, digits and _.
Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Marks the field required for people and the browser (the form’s rules decide).
Sourcepub fn placeholder(self, placeholder: &str) -> Self
pub fn placeholder(self, placeholder: &str) -> Self
Text shown in the empty field (for a select: its empty choice).
Sourcepub fn prefix(self, prefix: &str) -> Self
pub fn prefix(self, prefix: &str) -> Self
Text joined to the start of the field (“https://”, “$”).
Sourcepub fn span_full(self) -> Self
pub fn span_full(self) -> Self
Takes the form’s whole width (it has two columns on wider screens).
Sourcepub fn autocomplete(self, autocomplete: &str) -> Self
pub fn autocomplete(self, autocomplete: &str) -> Self
The browser’s autocomplete hint ("off", "email").
Sourcepub fn searchable(self) -> Self
pub fn searchable(self) -> Self
For a select: a box to type in that filters the options.
Sourcepub fn default_value(self, value: impl Serialize) -> Self
pub fn default_value(self, value: impl Serialize) -> Self
The value the create page starts with (the edit page shows the record’s).
Sourcepub fn only_on_create(self) -> Self
pub fn only_on_create(self) -> Self
Only on the create page.
Sourcepub fn only_on_edit(self) -> Self
pub fn only_on_edit(self) -> Self
Only on the edit page.
Sourcepub fn readonly_on_edit(self) -> Self
pub fn readonly_on_edit(self) -> Self
Shown but not changeable on the edit page (it is still sent, so the form’s rules see it).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Field
impl RefUnwindSafe for Field
impl Send for Field
impl Sync for Field
impl Unpin for Field
impl UnsafeUnpin for Field
impl UnwindSafe for Field
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<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