Welcome to Vanilla Breeze
This bell pulls live notifications from /go/notify/messages — the same contract documented at /docs/concepts/service-contracts/. Static articles like this one are the no-JS / no-backend fallback.
This bell pulls live notifications from /go/notify/messages — the same contract documented at /docs/concepts/service-contracts/. Static articles like this one are the no-JS / no-backend fallback.
Conditionally show or hide form sections based on another field's value. Hidden elements get hidden and inert attributes to bypass validation. Covers data-show-when and data-hide-when.
The data-show-when and data-hide-when attributes let you conditionally display form sections based on the value of another field. Hidden sections receive the hidden and inert attributes, which removes them from the tab order and bypasses any validation constraints inside. This is a combined page covering both attributes.
<select name="account-type"> <option value="personal">Personal</option> <option value="business">Business</option></select> <fieldset data-show-when="account-type=business"> <legend>Business Details</legend> <input name="company" placeholder="Company name"></fieldset>
Add data-show-when or data-hide-when to any element inside a form. The init script:
<form> ancestor (or the document if no form exists)change and input event listeners on the formhidden and inert on the conditional elementdata-conditional-init to prevent double-bindingBecause hidden elements receive the inert attribute, any required fields inside them will not block form submission. This lets you safely add validation to conditional sections without worrying about invisible required fields.
| Attribute | Format | Description |
|---|---|---|
data-show-when |
"name=value" or "name" |
Shows the element when the named field matches the value (equality check) or has any value (truthy check). |
data-hide-when |
"name=value" or "name" |
Hides the element when the condition is met. The inverse of data-show-when. |
data-conditional-init |
boolean | Set automatically to prevent double-binding. Do not set manually. |
The attribute value supports two formats:
| Syntax | Meaning | Example |
|---|---|---|
name=value |
Equality check — the named field must have this exact value | data-show-when="account-type=business" |
name |
Truthy check — the named field has any non-empty value, or the checkbox is checked | data-show-when="newsletter" |
Use data-hide-when for the inverse logic — the element is visible by default and hides when the condition matches.
<label> <input type="checkbox" name="gift" value="yes"> This is a gift</label> <form-field data-hide-when="gift=yes"> <label for="receipt">Send receipt to</label> <input type="email" id="receipt" name="receipt"></form-field>
Conditions work with radio button groups. The condition evaluates against the currently selected radio value within the named group.
<fieldset> <legend>Delivery</legend> <label><input type="radio" name="delivery" value="pickup"> Pickup</label> <label><input type="radio" name="delivery" value="ship"> Ship</label></fieldset> <fieldset data-show-when="delivery=ship"> <legend>Shipping Address</legend> <input name="address" placeholder="Street address"></fieldset>
Omit the =value part to use a truthy check. For checkboxes, this means the element shows when the checkbox is checked. For text inputs and selects, it shows when the field has any non-empty value.
<label> <input type="checkbox" name="newsletter"> Subscribe to newsletter</label> <form-field data-show-when="newsletter"> <label for="freq">Frequency</label> <select id="freq" name="frequency"> <option>Weekly</option> <option>Monthly</option> </select></form-field>
Conditions can reference any of the following field types by their name attribute:
The condition resolver looks for the referenced field within the closest <form> ancestor. If the conditional element is not inside a form, the resolver searches the entire document. This scoping prevents conflicts when multiple forms exist on the same page.
<!-- Scoped to closest <form> ancestor --><form> <select name="plan"> <option value="free">Free</option> <option value="pro">Pro</option> </select> <fieldset data-show-when="plan=pro"> <legend>Pro Features</legend> <input name="api-key" placeholder="API key"> </fieldset></form>
When a section is hidden, the inert attribute is applied alongside hidden. This means:
required fields inside the hidden section are excluded from form validationWhen the section becomes visible again, both hidden and inert are removed, restoring full interactivity and validation.
Hidden conditional elements use native hidden and inert attributes. The default browser behavior of hidden is display: none, which already works without any custom CSS.
/* Hidden conditional sections use native hidden + inert */[data-show-when][hidden],[data-hide-when][hidden] { display: none;} /* Optional: transition when revealing */[data-show-when],[data-hide-when] { transition: opacity 0.2s ease;}
All behavior is gated on data-conditional-init. Without JavaScript, the conditional sections render in their default visible state — progressive enhancement.
hidden attribute removes the element from visual display and the accessibility treeinert attribute ensures hidden content is completely non-interactive — no focus trapping in invisible fields