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
impl FieldConditions
Sourcepub fn visible(
self,
field: impl Into<String>,
rule: impl Fn(&FormContext<'_>) -> bool + Send + Sync + 'static,
) -> Self
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 () => ...).
Hides field when rule holds, as Filament’s ->hidden(fn () => ...).
Sourcepub fn visible_on(
self,
field: impl Into<String>,
operations: &[Operation],
) -> Self
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').
Hides field on the forms of operations, as Filament’s ->hiddenOn('edit').
Sourcepub fn disabled(
self,
field: impl Into<String>,
rule: impl Fn(&FormContext<'_>) -> bool + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn disabled_on(
self,
field: impl Into<String>,
operations: &[Operation],
) -> Self
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.
Sourcepub fn is_disabled(&self, field: &str, form: &FormContext<'_>) -> bool
pub fn is_disabled(&self, field: &str, form: &FormContext<'_>) -> bool
Whether field is disabled on form.
Sourcepub fn live(self, field: impl Into<String>) -> Self
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.
Sourcepub fn slug_from(
self,
field: impl Into<String>,
source: impl Into<String>,
) -> Self
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.
Sourcepub fn slug_locked_when(
self,
field: impl Into<String>,
rule: impl Fn(&FormContext<'_>) -> bool + Send + Sync + 'static,
) -> Self
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")
})Sourcepub fn is_slug_locked(&self, field: &str, form: &FormContext<'_>) -> bool
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.
Sourcepub fn slug_source(&self, field: &str) -> Option<&str>
pub fn slug_source(&self, field: &str) -> Option<&str>
The field field is filled from by slug_from, if any.
Sourcepub fn is_shown(&self, field: &str, form: &FormContext<'_>) -> bool
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.
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.
Sourcepub fn default_value(
self,
field: impl Into<String>,
value: impl Into<Value>,
) -> Self
pub fn default_value( self, field: impl Into<String>, value: impl Into<Value>, ) -> Self
Gives field the default value value on the create form, as Filament’s
->default(...): the create form shows it (a checkbox is ticked by true, a select has
the value chosen, a checkbox list or a repeater takes JSON such as ["a","b"]), and a
create whose request does not send the field saves it, as Laravel’s
$request->input('name', $default). The edit form always shows the stored value, as
Filament uses defaults on the Create page only. A field with no default shows blank, as
before.
An unticked checkbox sends nothing, so a checkbox default only ticks the box on the
create form: a create that does not send the checkbox saves false, as Laravel’s
$request->boolean(). A field hidden or disabled on the create form is not saved,
default or not. A later default for the same field replaces the earlier one.
Sourcepub fn default_with(
self,
field: impl Into<String>,
rule: impl Fn(&FormContext<'_>) -> Value + Send + Sync + 'static,
) -> Self
pub fn default_with( self, field: impl Into<String>, rule: impl Fn(&FormContext<'_>) -> Value + Send + Sync + 'static, ) -> Self
Gives field a default computed from the create form’s state, as Filament’s
->default(fn (Get $get) => ...): rule is given the create form’s FormContext
(no record, the signed-in user, and the form’s values so far: on the form shown, the
defaults of the fields before field in the form’s order; on a save, the values the
request sent and those defaults). Otherwise as
default_value.
Sourcepub fn has_default(&self, field: &str) -> bool
pub fn has_default(&self, field: &str) -> bool
Whether field has a default value on the create form.
Sourcepub fn default_form(&self, fields: &[FieldDef], user: &ActingUser) -> FormInput
pub fn default_form(&self, fields: &[FieldDef], user: &ActingUser) -> FormInput
The values the create form shows for user before anything is typed: the default of
each field of fields that has one, in the fields’ order, as form text.
Sourcepub fn with_defaults(
&self,
fields: &[FieldDef],
user: &ActingUser,
values: &FormInput,
) -> FormInput
pub fn with_defaults( &self, fields: &[FieldDef], user: &ActingUser, values: &FormInput, ) -> FormInput
values, a submitted create form, with the default of each field the request did not
send (FormInput::has is false), except a checkbox: an unticked checkbox sends
nothing, so it stays unticked. The panel calls it before it checks a create.
The sub-fields of the repeaters, groups and flexible content of fields that their
conditions hide in their own row, by the dotted path of their value, such as
fields.0.choices (a block’s: content.0.data.style), on the form for operation,
editing record, for user, whose fields hold values (a structured field’s value as
JSON text). A condition is keyed by the sub-field’s path without row numbers
(fields.choices) and reads its row’s values (see FormContext::row); a sibling the
row hides reads as blank. The panel leaves these sub-fields out of the form and out of
the saved value.
Trait Implementations§
Source§impl Clone for FieldConditions
impl Clone for FieldConditions
Source§impl Debug for FieldConditions
impl Debug for FieldConditions
Auto Trait Implementations§
impl !RefUnwindSafe for FieldConditions
impl !UnwindSafe for FieldConditions
impl Forget for FieldConditions
impl Freeze for FieldConditionswhere
*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,
PhantomData<(String, Arc<dyn Fn(&FormContext<'_>) -> Value + Sync + Send>)>: Freeze,
impl Move for FieldConditions
impl Send for FieldConditions
impl Sync for FieldConditions
impl Unpin for FieldConditions
impl UnsafeUnpin for FieldConditionswhere
*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,
PhantomData<(String, Arc<dyn Fn(&FormContext<'_>) -> Value + Sync + Send>)>: UnsafeUnpin,
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<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