pub struct Field {
pub name: &'static str,
pub label: &'static str,
pub kind: FieldKind,
pub required: bool,
}Expand description
One input on a create or edit form.
Fields§
§name: &'static strThe form field name. It matches a key of the record.
label: &'static strThe label shown next to the input.
kind: FieldKindThe input type, and how the value is read.
required: boolWhether the form rejects a blank value.
Implementations§
Source§impl Field
impl Field
Sourcepub fn check_required<'a>(
&self,
form: &'a FormInput,
errors: &mut FieldErrors,
) -> Option<&'a str>
pub fn check_required<'a>( &self, form: &'a FormInput, errors: &mut FieldErrors, ) -> Option<&'a str>
Returns the trimmed value of a required field. If it is missing or blank, records “
Sourcepub fn check_whole_number<T: FromStr>(
&self,
text: &str,
errors: &mut FieldErrors,
) -> Option<T>
pub fn check_whole_number<T: FromStr>( &self, text: &str, errors: &mut FieldErrors, ) -> Option<T>
Parses text as a whole number of type T. If it does not parse, records
“
Sourcepub fn check_number(&self, text: &str, errors: &mut FieldErrors) -> Option<f64>
pub fn check_number(&self, text: &str, errors: &mut FieldErrors) -> Option<f64>
Parses text as a number, whole or decimal, such as 42 or 42.5. Values that are
not finite (inf, NaN) are refused. If it does not parse, records
“
Sourcepub fn check_decimal<T: FromStr + Into<f64> + Copy>(
&self,
text: &str,
errors: &mut FieldErrors,
) -> Option<T>
pub fn check_decimal<T: FromStr + Into<f64> + Copy>( &self, text: &str, errors: &mut FieldErrors, ) -> Option<T>
Parses text as a decimal number of type T (f32 or f64), such as 9.5. A
value that is not finite (inf, NaN, or an f32 too large) is refused. If it
does not parse, records “
Sourcepub fn check_datetime(
&self,
text: &str,
errors: &mut FieldErrors,
) -> Option<NaiveDateTime>
pub fn check_datetime( &self, text: &str, errors: &mut FieldErrors, ) -> Option<NaiveDateTime>
Parses text as a date and time: YYYY-MM-DDTHH:MM as a date-time input sends it,
or with a space in place of the T, and with seconds when given. If it does not
parse, records “
Sourcepub fn check_choice(
&self,
text: &str,
choices: &[(&str, &str)],
errors: &mut FieldErrors,
) -> bool
pub fn check_choice( &self, text: &str, choices: &[(&str, &str)], errors: &mut FieldErrors, ) -> bool
Checks that text is the value of one of choices. If it is not, records
“Choose one of the options.” in errors and returns false.
Sourcepub fn check_date(
&self,
text: &str,
errors: &mut FieldErrors,
) -> Option<NaiveDate>
pub fn check_date( &self, text: &str, errors: &mut FieldErrors, ) -> Option<NaiveDate>
Parses text as a YYYY-MM-DD date. If it does not parse, records
“
Sourcepub fn check_email(
&self,
text: &str,
errors: &mut FieldErrors,
) -> Option<String>
pub fn check_email( &self, text: &str, errors: &mut FieldErrors, ) -> Option<String>
Checks that text, trimmed, is an email address, as the browser’s type="email"
input defines one: a local part of letters, digits and .!#$%&'*+/=?^_`{|}~-, an
@, and a domain of dot-separated labels of letters, digits and inner hyphens. If it
is not, records “
Sourcepub fn check_url(&self, text: &str, errors: &mut FieldErrors) -> Option<String>
pub fn check_url(&self, text: &str, errors: &mut FieldErrors) -> Option<String>
Checks that text, trimmed, is a URL as ACF’s URL field accepts one: an absolute URL
that parses, such as https://example.com/about, or a protocol-relative one with a
host, such as //cdn.example.com/lib.js. The javascript:, data: and vbscript:
schemes are refused in any case and with any whitespace or control characters around
them, because a link to one runs code. Otherwise records “
Sourcepub fn check_color(
&self,
text: &str,
errors: &mut FieldErrors,
) -> Option<String>
pub fn check_color( &self, text: &str, errors: &mut FieldErrors, ) -> Option<String>
Checks that text, trimmed, is a color as #rrggbb, and returns it in lowercase. If
it is not, records “
Sourcepub fn check_link(&self, text: &str, errors: &mut FieldErrors) -> Option<String>
pub fn check_link(&self, text: &str, errors: &mut FieldErrors) -> Option<String>
Checks that text is the JSON of a link, {"url": ..., "title": ..., "target": ...},
whose target is "" or "_blank" and whose URL is one ACF’s link picker stores: a URL
that passes check_url, a root-relative path (/about), an anchor
(#top) or a query (?a=b). A blank URL, // with no host and a script scheme are
refused. The title and target may be left out. Returns the link as JSON text with
all three keys. Otherwise records “
Sourcepub fn check_value(
&self,
text: &str,
errors: &mut FieldErrors,
) -> Option<String>
pub fn check_value( &self, text: &str, errors: &mut FieldErrors, ) -> Option<String>
Checks text against the field’s kind, and returns the text to store, for the kinds
whose value is text: email, URL, radio, color, image, file, link, wysiwyg, post
object, relationship, taxonomy, user, repeater, group, flexible content, gallery and
clone. The structured kinds (relationship, repeater, group, flexible content, gallery,
clone) take JSON text, check each value against its sub-field, and return the checked
JSON; reading it back gives the same structure. An empty list or group is blank, so a
required field records “
The other kinds have checks of their own (such as
check_whole_number); for them text is returned
unchanged.
Trait Implementations§
impl Copy for Field
impl Eq for Field
impl StructuralPartialEq for Field
Auto Trait Implementations§
impl Forget for Field
impl Freeze for Field
impl Move 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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