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 disabled( self, field: impl Into<String>, rule: impl Fn(&FormContext<'_>) -> bool + Send + Sync + 'static, ) -> Self

Shows field but does not let the user change it when rule holds, as Filament’s ->disabled(fn () => ...): its input is disabled and, as in Filament, a disabled field is not saved, so its stored value is kept whatever a request sends. A later disabled or disabled_on for the field replaces the earlier one.

Source

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

Disables field on the forms of operations, as Filament’s ->disabledOn('edit'): such as a key that is set when the record is created and locked after its first save.

Source

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

Whether field is disabled on form.

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 slug_from( self, field: impl Into<String>, source: impl Into<String>, ) -> Self

Fills the field field with the slug of the field source as the user types, until the user edits field by hand, as Filament’s documented slug pattern: ->afterStateUpdated(...) on the title sets slug to Str::slug($state) unless the slug no longer matches Str::slug($old). Filament writes that with a closure on the server; the panel’s script does it in the browser, so it needs no round trip. The slug is the text in lowercase ASCII, accents removed, with each run of other characters turned into one -, as Str::slug gives it. The value is not checked: validate still checks it.

On the edit form, a slug that is not the slug of the stored title counts as edited by hand, so it is not replaced. slug_locked_when stops it from following the title at all, such as once the record is published.

Source

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

Stops the slug field field from following its source on the edit form of a record whose stored slug is not blank, when rule holds, such as when the stored record is published: the slug of a published post’s URL then stays as it is when the title changes. On the create form, and while rule fails (such as for a draft), the slug follows the title as slug_from says. The user can still edit the slug by hand. The input is marked data-ignite-slug-locked, which the panel’s script reads.

Filament’s slug example has no such rule: it stops when the user has edited the slug. Ignite keeps that, and adds this one.

ⓘ
conditions
    .slug_from("slug", "title")
    .slug_locked_when("slug", |form| {
        form.record().and_then(|r| r.get("status")).and_then(|s| s.as_str()) == Some("publish")
    })
Source

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

Whether the slug field field no longer follows its source on form: the form edits a record whose stored field is not blank, and the rule of slug_locked_when holds.

Source

pub fn slug_source(&self, field: &str) -> Option<&str>

The field field is filled from by slug_from, if any.

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§

§

impl !RefUnwindSafe for FieldConditions

§

impl !UnwindSafe for FieldConditions

§

impl Forget for FieldConditions

§

impl Freeze for FieldConditions
where *const u8 is !null: Freeze, PhantomData<(String, Arc<dyn Fn(&FormContext<'_>) -> bool + Sync + Send>)>: Freeze, *const LeafNode<String, SetValZST> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, SetValZST)>>: Freeze, PhantomData<(String, String)>: Freeze,

§

impl Move for FieldConditions

§

impl Send for FieldConditions
where RawTable<(String, Arc<dyn Fn(&FormContext<'_>) -> bool + Sync + Send>)>: Send, NodeRef<Owned, String, SetValZST, LeafOrInternal>: Send, BoxRaw<(String, SetValZST)>: Send, RawTable<(String, String)>: Send,

§

impl Sync for FieldConditions
where RawTable<(String, Arc<dyn Fn(&FormContext<'_>) -> bool + Sync + Send>)>: Sync, NodeRef<Owned, String, SetValZST, LeafOrInternal>: Sync, BoxRaw<(String, SetValZST)>: Sync, RawTable<(String, String)>: Sync,

§

impl Unpin for FieldConditions
where *const u8 is !null: Unpin, Arc<dyn Fn(&FormContext<'_>) -> bool + Sync + Send>: Unpin, *const LeafNode<String, SetValZST> is !null: Unpin, Box<(String, SetValZST)>: Unpin,

§

impl UnsafeUnpin for FieldConditions
where *const u8 is !null: UnsafeUnpin, PhantomData<(String, Arc<dyn Fn(&FormContext<'_>) -> bool + Sync + Send>)>: UnsafeUnpin, *const LeafNode<String, SetValZST> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, SetValZST)>>: UnsafeUnpin, PhantomData<(String, String)>: UnsafeUnpin,

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