Skip to main content

FieldConditions

Struct FieldConditions 

Source
pub struct FieldConditions { /* private fields */ }
Expand description

The conditions of a form’s fields, by field name, and the fields that are live. Each method takes the field’s name and returns the conditions, so they chain.

As in Filament, a field has one hidden condition and one visible condition, and shows only when its hidden condition fails and its visible condition holds. A later hidden or hidden_on for the same field replaces the earlier one, and so does a later visible or visible_on. A field with no condition always shows.

Implementations§

Source§

impl FieldConditions

Source

pub fn new() -> Self

No conditions: every field shows, and none is live.

Source

pub fn visible( self, field: impl Into<String>, rule: impl Fn(&FormContext<'_>) -> bool + Send + Sync + 'static, ) -> Self

Shows field only when rule holds, as Filament’s ->visible(fn () => ...).

Source

pub fn hidden( self, field: impl Into<String>, rule: impl Fn(&FormContext<'_>) -> bool + Send + Sync + 'static, ) -> Self

Hides field when rule holds, as Filament’s ->hidden(fn () => ...).

Source

pub fn visible_on( self, field: impl Into<String>, operations: &[Operation], ) -> Self

Shows field only on the forms of operations, as Filament’s ->visibleOn('edit').

Source

pub fn hidden_on( self, field: impl Into<String>, operations: &[Operation], ) -> Self

Hides field on the forms of operations, as Filament’s ->hiddenOn('edit').

Source

pub fn live(self, field: impl Into<String>) -> Self

Makes field live, as Filament’s ->live(): when its value changes in the browser, the form’s fields are shown again for the new value, so a field whose condition reads it with FormContext::get appears or disappears. The browser sends the change when the input fires change: at once for a select, a checkbox or a radio, and when a text input loses focus.

Source

pub fn is_live(&self, field: &str) -> bool

Whether field is live.

Source

pub fn is_empty(&self) -> bool

Whether no field has a condition or is live.

Source

pub fn is_shown(&self, field: &str, form: &FormContext<'_>) -> bool

Whether field shows in form: its hidden condition, if any, fails and its visible condition, if any, holds.

Source

pub fn hidden_fields( &self, fields: &[FieldDef], operation: Operation, record: Option<&Row>, user: &ActingUser, values: &FormInput, ) -> BTreeSet<String>

The names of the fields that are hidden on the form for operation, editing record, for user, whose fields hold values.

A condition that reads a hidden field gets the field’s stored value, not the one in values, so a request cannot show a field by sending a value for a field it may not see. The conditions run again until the hidden fields settle.

Trait Implementations§

Source§

impl Clone for FieldConditions

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 Debug for FieldConditions

Source§

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

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

impl Default for FieldConditions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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