惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
K
Kaspersky official blog
A
Arctic Wolf
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 热门话题
N
News | PayPal Newsroom
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
W
WeLiveSecurity
Know Your Adversary
Know Your Adversary
博客园 - Franky
T
Tenable Blog
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Help Net Security
Help Net Security
WordPress大学
WordPress大学
T
The Exploit Database - CXSecurity.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
S
Security Affairs
J
Java Code Geeks
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Apple Machine Learning Research
Apple Machine Learning Research
NISL@THU
NISL@THU
O
OpenAI News
The Cloudflare Blog
月光博客
月光博客
Google Online Security Blog
Google Online Security Blog
V
V2EX
罗磊的独立博客
美团技术团队
博客园 - 三生石上(FineUI控件)
Security Latest
Security Latest
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
L
LINUX DO - 最新话题
Hacker News - Newest:
Hacker News - Newest: "LLM"
大猫的无限游戏
大猫的无限游戏

Aaron Gustafson: Latest Posts & Links

LLM biased against accessible code (Claude Code issue #56079) :: Aaron Gustafson Can Your AI Pass the Accessibility Test? :: Aaron Gustafson Can Your AI Pass the Accessibility Test? :: Aaron Gustafson Fixing Accessibility After the Fact Is Too Late :: Aaron Gustafson Easy Data-entry Verification with a Web Component :: Aaron Gustafson Artificial Intelligence Has One Chance To Get Accessibility Right :: Aaron Gustafson Building a general-purpose accessibility agent—and what we learned in the process :: Aaron Gustafson Fixing Accessibility After the Fact Is Too Late :: Aaron Gustafson AI companies will fail. We can salvage something from the wreckage :: Aaron Gustafson Accessible faux-nested interactive controls :: Aaron Gustafson AI-assisted coding transforms PDF to web app using NYS Design System :: Aaron Gustafson Modern CSS Feature Support For Shadow DOM :: Aaron Gustafson AI is locking people out. At Scale. :: Aaron Gustafson The Incredible Overcomplexity of the Shadcn Radio Button :: Aaron Gustafson Accessibility in the End of Deterministic Design (Again) :: Aaron Gustafson Making keyboard navigation effortless :: Aaron Gustafson The WebAIM Million: The 2026 report on the accessibility of the top 1,000,000 home pages :: Aaron Gustafson Under the hood of MDN’s new frontend :: Aaron Gustafson Endgame for the Open Web :: Aaron Gustafson slideVars :: Aaron Gustafson AI is accidently making documentation accessible :: Aaron Gustafson Design systems can’t automate away all of your accessibility considerations :: Aaron Gustafson The Power of ‘No’ in Internet Standards :: Aaron Gustafson Nice Select :: Aaron Gustafson Visual Validation Feedback for Form Fields :: Aaron Gustafson Never Lose Form Progress Again :: Aaron Gustafson Different contexts, different tools, same person :: Aaron Gustafson Accessibility Assistant for Figma v52 :: Aaron Gustafson Some blind fans to experience Super Bowl with tactile device that tracks ball :: Aaron Gustafson Why we teach our students progressive enhancement :: Aaron Gustafson Repeatable Form Fields Made Simple :: Aaron Gustafson A Production-Ready Web Component Starter Template :: Aaron Gustafson Fullscreen Video and Iframes Made Easy :: Aaron Gustafson Dynamic Datalist: Autocomplete from an API :: Aaron Gustafson Lazy Loading Images Based on Screen Size :: Aaron Gustafson A Web Component for Obfuscating Form Fields :: Aaron Gustafson Forrester Research: As technology has evolved, so has the need for accessibility :: Aaron Gustafson Creating a more accessible web with ARIA Notify :: Aaron Gustafson Optimizing Your Codebase for AI Coding Agents :: Aaron Gustafson Default Isn’t Design :: Aaron Gustafson Identifying Accessibility Data Gaps in CodeGen Models :: Aaron Gustafson Designing for Distress: Understanding Users in Crisis :: Aaron Gustafson Why I'm Betting Against AI Agents in 2025 (Despite Building Them) :: Aaron Gustafson Why AI Won’t Destroy Us with Microsoft’s Brad Smith :: Aaron Gustafson Learning Web Design, 6th Edition is out! :: Aaron Gustafson
A Web Component for Conditionally Displaying Fields :: Aaron Gustafson
Aaron Gustafson · 2025-10-20 · via Aaron Gustafson: Latest Posts & Links

Building on my recent work in the form utility space, I’ve created a new web component that allows you to conditionally display form fields based on the values of other fields: form-show-if.

This component tackles a common UX pattern that HTML doesn’t natively support. You know the scenario—you have a form where certain fields should only appear when specific conditions are met. Maybe you want to show shipping address fields only when someone checks “Ship to different address,” or display a text input for “Other” when someone selects that option from a dropdown. This web component makes that setup effortless — and declarative.

You set up form-show-if like this:

<form-show-if conditions="contact_method=phone">
  <label for="phone"
    >Phone Number
    <input type="tel" id="phone" name="phone" />
  </label>
</form-show-if>

You wrap any field and its label in the component and then declare the conditions under which it should be displayed in the conditions attribute.

Defining the display conditions

Each condition is a key/value pair where the key aligns to the name of the field you need to observe and the value is the value that triggers the display. If any value should trigger the display, use an asterisk (*) as the value. In the example above, the field will become visible only if — in a theoretical contact method choice — a user chooses “phone” as the method they want used.

The conditions attribute can be populated with as many dependencies as you need. Multiple conditions are separated by double vertical pipes (||), as in this example:

<form-show-if conditions="contact_method=phone||contact_method=text_message">
  <label for="phone-number"
    >Phone Number
    <input type="tel" id="phone" name="phone" />
  </label>
</form-show-if>

Here the field depends on one of the following conditions being true:

  1. the field matching [name="contact_method"] has a value of “phone” or
  2. the field matching [name="contact_method"] has a value of “text_message”

If the field you reference doesn’t exist, no errors will be thrown—it will just quietly exit.

Customizing the show/hide behavior

By default, the component uses the hidden attribute to hide the wrapped content when it’s not needed. But you can customize this behavior using CSS classes instead:

<form-show-if
  conditions="shipping-method=express"
  disabled-class="fade-out"
  enabled-class="fade-in"
>
  <label for="delivery-date"
    >Express Delivery Date
    <input type="date" id="delivery-date" name="delivery-date" />
  </label>
</form-show-if>

When using custom classes:

  • disabled-class is applied when the condition is not met (field should be hidden)
  • enabled-class is applied when the condition is met (field should be shown)

Both are optional. Just remember that if you define a disabled-class, the hidden attribute will not be used — you will need to accessibly hide the content yourself.

This gives you complete control over the visual presentation. You could use CSS transitions for smooth animations, apply different styling states, or integrate with your existing design system’s utility classes.

Handling form state properly

The component doesn’t just toggle visibility—it also manages the form state correctly. When fields are hidden, they’re automatically disabled using the disabled attribute. If there are any sibling fields in the component, they will be disabled as well. This prevents these fields from being submitted with the form and ensures they don’t interfere with form validation.

When conditions are met and fields become visible, they’re re-enabled automatically. This behavior works seamlessly with both native form validation and custom validation scripts.

Real-world examples

Here are some practical use cases where this component shines:

“Other” option handling:

<fieldset>
  <legend>How did you hear about us?</legend>

  <label><input type="radio" name="source" value="google" /> Google</label>
  <label><input type="radio" name="source" value="friend" /> Friend</label>
  <label><input type="radio" name="source" value="other" /> Other</label>

  <form-show-if conditions="source=other">
    <label for="source-other"
      >Please specify
      <input type="text" id="source-other" name="source-other" />
    </label>
  </form-show-if>
</fieldset>

Specific value matching:

<form-show-if conditions="email=test@example.com">
  <label for="debug-info"
    >Debug Information
    <textarea id="debug-info" name="debug-info"></textarea>
  </label>
  <small>This field only shows for test accounts</small>
</form-show-if>

Progressive enhancement in action

Like all good web components, form-show-if follows progressive enhancement principles. If JavaScript fails to load or the browser doesn’t support custom elements, your form still works—users just see all the fields all the time. Not ideal for the user experience, but nothing breaks either.

The component is lightweight, has no dependencies, and works in all modern browsers.

Demo

I’ve put together a comprehensive demo showing various use cases and configurations over on GitHub.

The demo includes examples of:

  • Basic show/hide functionality
  • Multiple condition logic
  • Custom CSS class integration
  • Complex form scenarios with radio buttons and checkboxes
  • Different field grouping approaches

Grab it

You can view the entire project (and suggest enhancements) over on the form-show-if component’s GitHub repo. The component is available as both a standard script and an ES module, so you can integrate it however works best for your project.

Installation is straightforward—just include the script in your page and start using the form-show-if element. No build step required, no framework dependencies, just clean, standards-based progressive enhancement.