Web component / Shared labels

<form-fieldset-progress>

Give several forms the same navigation and review wording. See the README for installation and the full API.

Set the page’s wording once

One inline JSON script supplies defaults for both forms on this page. These labels use an application’s vocabulary; the same configuration can hold translations. Translate your authored legends and fields too. For a single form, start with label attributes.

Enter a name, continue to Preferences, then review your answers. Empty notes and the two checkboxes show the shared review wording. Without JavaScript, all input sections and Submit remain available; no review or navigation is generated.

<script type="application/json" data-form-fieldset-progress-config>
{
  "previous-label": "Back to {legend}",
  "next-label": "Continue to {legend}",
  "review-label": "Check your application",
  "review-empty-label": "Not answered",
  "review-checked-label": "Yes",
  "review-unchecked-label": "No"
}
</script>

<form-fieldset-progress review-panel>
  <form>
    <fieldset><legend>Contact</legend>
      <label>Name <input name="name" required /></label>
    </fieldset>
    <fieldset><legend>Preferences</legend>
      <label>Notes <textarea name="notes"></textarea></label>
      <label><input name="updates" type="checkbox" checked /> Email updates</label>
      <label><input name="post" type="checkbox" /> Postal updates</label>
    </fieldset>
    <button type="submit">Send application</button>
  </form>
</form-fieldset-progress>
Contact
Preferences

Change one form’s button

This delivery form inherits the page’s defaults but overrides next-label. Its button keeps this wording when the shared labels change.

<form-fieldset-progress review-panel
  next-label="Next delivery step">
  <form>
    <fieldset><legend>Delivery address</legend>
      <label>City <input name="city" /></label>
    </fieldset>
    <fieldset><legend>Delivery notes</legend>
      <label>Notes <textarea name="notes"></textarea></label>
    </fieldset>
    <button type="submit">Save delivery details</button>
  </form>
</form-fieldset-progress>
Delivery address
Delivery notes

Update wording without starting over

While either form is on review, choose Use shorter wording. The generated title and empty-answer message change in place. The active section and captured answers stay put; Back still lets you edit them. This demo intercepts submissions without sending data when JavaScript is available.

Editing JSON alone doesn’t update existing forms. Call refreshLabels() on each ready instance. If configuration is invalid, it returns false and emits an error without changing the working UI. Correct the JSON and call it again. See the shared-label reference for validation and recovery details.

const script = document.querySelector(
  '[data-form-fieldset-progress-config]',
);
const labels = JSON.parse(script.textContent);
labels['review-label'] = 'Your answers';
labels['review-empty-label'] = 'No answer';
script.textContent = JSON.stringify(labels);
const updated = Array.from(
  document.querySelectorAll('form-fieldset-progress'),
  (element) => element.refreshLabels(),
).every(Boolean);