form-required-if via esm.sh

This page loads the component class from esm.sh and registers it manually. See the README.

Select Email, then provide an email address. If JavaScript is unavailable or the module fails to load, the fields still work: follow that instruction yourself. Production forms must also validate on the server. This demo does not send your details. It uses method="dialog" outside a dialog, so native validation still works but valid entries don’t navigate or send a request. Your entries stay in place even if registration or the component module fails.

Manual class registration

<form method="dialog">
<label for="contact-method">Preferred contact method</label>
<select id="contact-method" name="contact-method">
  <option value="">Select one</option>
  <option value="email">Email</option>
  <option value="phone">Phone</option>
</select>
<form-required-if conditions="contact-method=email" indicator=" (required)">
  <label for="email">Email (required when email selected)</label>
  <input type="email" id="email" name="email" />
</form-required-if>
<button type="submit">Check details</button>
<button type="reset">Reset</button>
</form>