Conditional Visibility
Conditional visibility mounts or unmounts a field or fieldset in the browser, based on the current value of another field:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\Combobox;
use InertiaUI\Forms\Fields\TextInput;
return [
Combobox::make('contact_method')
->options([
'email' => 'Email',
'phone' => 'Phone',
]),
TextInput::make('phone_number')
->visibleWhen('contact_method', 'phone'),
TextInput::make('email_notes')
->hiddenWhen('contact_method', 'phone'),
TextInput::make('contact_details')
->visibleWhen('contact_method', operator: 'not_empty'),
Fieldset::make()
->legend('Phone follow-up')
->visibleWhen('contact_method', 'phone')
->fields([
TextInput::make('phone_extension'),
]),
];To check a value against a list, prefer the visibleWhenIn and hiddenWhenIn methods over passing the operator yourself:
use InertiaUI\Forms\Fields\TextInput;
TextInput::make('vat_id')
->visibleWhenIn('country', ['NL', 'BE', 'DE']);
TextInput::make('domestic_notes')
->hiddenWhenIn('country', ['NL', 'BE', 'DE']);Operators
Besides matching an exact value, the visibleWhen and hiddenWhen methods accept an operator to compare with. The following operators are available:
| Operator | Meaning |
|---|---|
= | Visible when the referenced value matches. |
!= | Visible when the referenced value does not match. |
> | Visible when the referenced value is numerically greater than the configured value. |
>= | Visible when the referenced value is numerically greater than or equal to the configured value. |
< | Visible when the referenced value is numerically less than the configured value. |
<= | Visible when the referenced value is numerically less than or equal to the configured value. |
in | Visible when the referenced value appears in the configured array. |
not_in | Visible when the referenced value does not appear in the configured array. |
contains | Visible when the referenced array or string contains the configured value. |
empty | Visible when the referenced value is null, undefined, an empty string, or an empty array. |
not_empty | Visible when the referenced value is not empty. |
truthy | Visible when the referenced value is truthy. Empty values are treated as false. |
falsy | Visible when the referenced value is falsy. Empty values are treated as false. |
Named arguments keep a comparison readable:
use InertiaUI\Forms\Fields\TextInput;
TextInput::make('guardian_name')
->visibleWhen('age', operator: '<', value: 18);The field path may be a dotted path, such as address.country.
Numeric comparisons convert numbers and numeric strings explicitly. Non-numeric values never match a numeric comparison operator. Equality, in, and array contains use the same numeric normalization, so 10 and '10' match.
The empty, not_empty, truthy, and falsy operators don't serialize a value.
Paths Inside Repeaters and Blocks
A Repeater holds a list of rows, so the same field exists once per row. Inside a repeater schema, a field path resolves against the row the field is rendered in, not against the whole form. Take this form data as an example:
$data = [
'contact_method' => 'phone', // Top-level field
'contacts' => [
['type' => 'business', 'company_name' => 'Acme'], // Row 0
['type' => 'personal', 'company_name' => null], // Row 1
],
];The visibleWhen('type', 'business') condition below reads the type of its own row. Each row evaluates the condition against its own values, so row 0 shows company_name and row 1 hides it:
use InertiaUI\Forms\Fields\Combobox;
use InertiaUI\Forms\Fields\Repeater;
use InertiaUI\Forms\Fields\TextInput;
Repeater::make('contacts')
->schema([
Combobox::make('type')->options([
'personal' => 'Personal',
'business' => 'Business',
]),
TextInput::make('company_name')
->visibleWhen('type', 'business'),
]);To read a field outside the row, prefix the path with $.. This condition reads the top-level contact_method, so it resolves the same way for every row:
use InertiaUI\Forms\Fields\TextInput;
TextInput::make('phone_follow_up')
->visibleWhen('$.contact_method', 'phone');The $. prefix always refers to the outermost form data. In a repeater nested inside another repeater, it still reaches the top-level form instead of the parent row.
Blocks set schemas work the same way. A plain path reads the current block's own data, and $. reads the top-level form data.
Groups
Chaining several visibleWhen calls serializes them as an and group. To group conditions explicitly, you may use the visibleWhenAll, visibleWhenAny, and visibleWhenNot methods:
use InertiaUI\Forms\Fields\TextInput;
TextInput::make('business_phone_note')
->visibleWhenAll(fn ($visibility) => $visibility
->where('contact_method', 'phone')
->where('customer_type', 'business'));
TextInput::make('priority_contact_note')
->visibleWhenAny(fn ($visibility) => $visibility
->where('contact_method', 'phone')
->where('customer_type', 'business'));
TextInput::make('non_business_note')
->visibleWhenNot(fn ($visibility) => $visibility
->where('customer_type', 'business'));Use a group only for the part of the condition that needs one. This field is visible for team-plan accounts, unless the account is suspended or its billing is overdue:
use InertiaUI\Forms\Fields\Textarea;
Textarea::make('renewal_note')
->visibleWhen('plan', 'team')
->visibleWhenNot(fn ($visibility) => $visibility
->where('account_status', 'suspended')
->where('billing_status', 'overdue'));The first call is a normal condition. The visibleWhenNot group evaluates to false when any of its conditions matches, so both blocked states must be absent for the field to render.
Each root visibility configuration includes an inferred dependsOn array with the referenced field paths. This array is metadata only. The current frontend renderers already evaluate visibility reactively from the form data, and they need no extra configuration.
Behavior
The Vue and React renderers remove hidden fields and fieldsets from the DOM, so their controls leave the tab order and the accessibility tree. Their values stay in the Inertia form data unless clearWhenHidden clears them.
To clear a field's client-side value once it changes from visible to hidden, call the clearWhenHidden method:
use InertiaUI\Forms\Fields\TextInput;
TextInput::make('phone_number')
->visibleWhen('contact_method', 'phone')
->clearWhenHidden();The same method on a fieldset clears every submitted child once the fieldset changes from visible to hidden:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;
Fieldset::make([
TextInput::make('phone_extension'),
TextInput::make('phone_notes'),
])
->visibleWhen('contact_method', 'phone')
->clearWhenHidden();Clearing is opt-in, so fields without clearWhenHidden keep their current value while hidden. Fields that are hidden when the form mounts aren't cleared. Clearing only happens after a visible field becomes hidden in the browser, and it also removes the field's validation errors.
Built-in fields clear to the same empty shape their controls use:
Checkboxuses its configuredfalseValue, andToggleuses its configuredoffValue.CheckboxGroup,Repeater, andBlocksuse[].KeyValueuses[]insinglemode and{}inkeyedmode.Comboboxuses[]for tags and multiple selections, andnullfor a single choice or record.TextInput,Slug,Textarea,Hidden, andOtpInputuse an empty string.Composeruses an empty string, or{ text: '', attachments: [] }when attachments are enabled.- A plain
Linkuses an empty string. A structured link uses{ url: '' }, and also includes emptylabelortargetkeys when those options are enabled. - Other built-in fields and custom fields use
null, unless their renderer defines a more specific shape.
Validation
Inertia Forms evaluates the same visibility conditions against the submitted data when a request is attached. Hidden fields receive Laravel's exclude validation rule, so their own rules are skipped and they're omitted from the validate and validated output. Hidden fieldsets exclude each child field the same way.
Repeater rows and block items are evaluated per submitted index, so one row may require a field while another row excludes it. A required rule therefore means "required when visible". Precognitive validation applies the same server-side exclusion before the existing Precognition-Validate-Only error filtering runs.
Wizards
In a wizard, the browser step navigation omits each step whose fieldset is hidden or has no visible fields. Visibility changes keep the current step index within the list of visible steps.
Limits
Editor internals and file upload internals don't get nested visibility semantics from this feature.
Visibility Is Not Authorization
Conditional visibility is presentation logic, not access control. A field hidden by visibleWhen or hiddenWhen is still part of the serialized form, so the browser may react to the form data. Don't use visibility for permissions or secrets.
Use authorizedWhen() for fields that shouldn't be sent to the frontend for the current user or request. Authorization runs before visibility, so unauthorized fields are removed before the frontend evaluates any visibility rules.
The clearWhenHidden method only clears a client-side value after a visible field becomes hidden. Authorization removes the field from the initial data, and skips its validation rules, before the browser receives the form.