Skip to main content

Field

Struct Field 

Source
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 str

The form field name. It matches a key of the record.

§label: &'static str

The label shown next to the input.

§kind: FieldKind

The input type, and how the value is read.

§required: bool

Whether the form rejects a blank value.

Implementations§

Source§

impl Field

Source

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 “

Source

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 “

Source

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 “

Source

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 “

Source

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 “

Source

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.

Source

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 “

Source

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 “

Source

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 “

Source

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 “

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 “

Source

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§

Source§

impl Clone for Field

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Field

Source§

impl Debug for Field

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Field

Source§

impl From<Field> for FieldDef

Source§

fn from(field: Field) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Field

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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