View laravel-hotwire on GitHub
1M
v0.91.0
Search 71 components and 72 controllers by name, category or description.
Conditional Field
Dependent form block with declarative server and client visibility rules
One trigger, multiple dependents
The state prop keeps the server-rendered first paint aligned, while | matches either value at runtime.
<hw:form
method="post"
action="#"
conditional-fields
:state="['request_type' => 'bug']"
>
<div class="grid gap-4">
<hw:field name="request_type" label="Request type">
<hw:select
:options="['bug' => 'Bug', 'feature' => 'Feature', 'other' => 'Other']"
selected="bug"
/>
</hw:field>
<hw:conditional-field when="request_type=bug|feature">
<hw:field name="details" label="Technical details">
<hw:textarea placeholder="What should the team know?" />
</hw:field>
</hw:conditional-field>
<hw:conditional-field when="request_type=other">
<hw:field name="other_reason" label="Tell us what you need">
<hw:input placeholder="Describe your request" />
</hw:field>
</hw:conditional-field>
</div>
</hw:form>
Checkbox state
Use :checked and :unchecked for boolean controls. A single-field dependent can opt into as="div".
<hw:form method="post" action="#" conditional-fields>
<div class="grid gap-4">
<label class="flex items-center gap-2">
<hw:checkbox name="needs_invoice" value="1" />
<span>Request a company invoice</span>
</label>
<hw:conditional-field when="needs_invoice=:checked">
<div class="grid gap-4 sm:grid-cols-2">
<hw:field name="company_name" label="Company name">
<hw:input placeholder="Acme Inc." />
</hw:field>
<hw:field name="tax_id" label="Tax ID">
<hw:input placeholder="00.000.000/0001-00" />
</hw:field>
</div>
</hw:conditional-field>
<hw:conditional-field
as="div"
when="needs_invoice=:unchecked"
class="rounded-lg border border-dashed p-4 text-sm text-muted-foreground"
>
A personal receipt will be issued by default.
</hw:conditional-field>
</div>
</hw:form>
Compound array rule
Array rules combine fields with AND; an array of accepted values keeps OR conditions readable.
<hw:form
method="post"
action="#"
conditional-fields
:state="['plan' => 'enterprise', 'region' => 'international']"
>
<div class="grid gap-4">
<div class="grid gap-4 sm:grid-cols-2">
<hw:field name="plan" label="Plan">
<hw:select
:options="['starter' => 'Starter', 'enterprise' => 'Enterprise']"
selected="enterprise"
/>
</hw:field>
<hw:field name="region" label="Billing region">
<hw:select
:options="['local' => 'Local', 'international' => 'International', 'global' => 'Global']"
selected="international"
/>
</hw:field>
</div>
<hw:conditional-field :when="[
'plan' => 'enterprise',
'region' => ['international', 'global'],
]">
<hw:field
name="billing_contact"
label="Global billing contact"
description="Required for Enterprise plans billed outside the local region."
>
<hw:input type="email" placeholder="billing@example.com" />
</hw:field>
</hw:conditional-field>
</div>
</hw:form>