defmodule PyrauiWeb.DocsLive.ConditionalFormDocs do use PyrauiWeb, :html def render(assigns) do ~H"""

Conditional Form

Conditional / dynamic form component where fields appear/disappear based on user input.

Basic Usage

<:field name="user_type" type="select" options={["individual", "business"]} /> <:conditional_field show_if={%{"user_type" => "business"}}>

    <.conditional_form id="dynamic-form">
      <:field name="user_type" type="select" options={["individual", "business"]} />
      <:conditional_field show_if={%{"user_type" => "business"}}>
        <div class="mb-4">
          <label for="company_name-input">Company Name</label>
          <input type="text" id="company_name-input" name="company_name" />
        </div>
      </:conditional_field>
    </.conditional_form>
            

Subscription Upgrades

Guided Upsell

Unlock tailored add-ons once a plan tier is selected. Annual billing surfaces an incentive banner automatically.

Perfect for pricing pages, upgrade modals, and checkout flows with progressive disclosure.

<:field name="plan" type="select" label="Plan tier" options={["Starter", "Growth", "Enterprise"]} /> <:conditional_field show_if={%{"plan" => "Growth"}}>

Growth perks

Enable collaboration seats and workflow automation once you graduate past Starter.

<:conditional_field show_if={%{"plan" => "Enterprise"}}>

Enterprise onboarding

<:field name="billing_cycle" type="select" label="Billing cadence" options={["Monthly", "Quarterly", "Annual"]} /> <:conditional_field show_if={%{"billing_cycle" => "Annual"}}>

Annual bonus

Annual customers capture a 15% discount and concierge migration support.

Notification Preferences

<:field name="send_updates" type="checkbox" label="Send product updates" /> <:conditional_field show_if={%{"send_updates" => true}}>

Update cadence

<:field name="preferred_channel" type="select" label="Priority channel" options={["Email", "SMS", "Push", "Slack"]} /> <:conditional_field show_if={%{"preferred_channel" => ["SMS", "Push"]}}>

We'll send a one-time verification code to confirm delivery.

Why it works

Checkbox toggles persist values as booleans, so show_if: %{"send_updates" => true} unlocks cadence controls instantly.

Passing a list into show_if supports multi-value branches without extra hooks. Here, both SMS and Push reveal device verification.

The hook listens to the entire form, so you can mix and match select, checkbox, and text inputs for progressive guidance.

""" end end