npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aarongustafson/form-matching-fields

v1.0.0

Published

Web component that automatically adds validation rules that ensure the values of descendent fields match.

Downloads

87

Readme

form-matching-fields Web Component

npm version Build Status

Web component wrapper that adds additive validation to ensure two text-type fields match.

Demo

Live Demo (Source)

Additional demos:

Installation

npm install @aarongustafson/form-matching-fields

Usage

Option 1: Auto-define the custom element (easiest)

Import the package to automatically define the <form-matching-fields> custom element:

import '@aarongustafson/form-matching-fields';

Or use the define-only script in HTML:

<script
  src="./node_modules/@aarongustafson/form-matching-fields/define.js"
  type="module"
></script>

Option 2: Import the class and define manually

Import the class and define the custom element with your preferred tag name:

import { FormMatchingFieldsElement } from '@aarongustafson/form-matching-fields/form-matching-fields.js';

customElements.define('my-custom-name', FormMatchingFieldsElement);

Basic Example

<form-matching-fields>
  <label for="password">Password</label>
  <input id="password" type="password" required />

  <label for="password-again">Password again</label>
  <input id="password-again" type="password" required />
</form-matching-fields>

How Matching Works

This component intentionally keeps matching behavior simple:

  • It only looks at descendant input controls.
  • It only considers text-type inputs: text, email, password, search, tel, and url.
  • It ignores disabled and readonly fields.
  • It always compares the first two eligible fields.
  • It only applies mismatch validation when both fields are non-empty.
  • It pins mismatch validation to the second field.

Validation Stacking Behavior

The component does not replace native or existing custom validation:

  • If the second field already has native validation issues (such as required or type mismatch), the component does not apply a mismatch message.
  • If the second field already has a custom validity message, the component does not replace it.
  • The component only clears a mismatch message that it previously set itself.

Attributes

| Attribute | Type | Default | Description | | -------------------- | -------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------- | | validation-message | string | The fields “{label_1}” and “{label_2}” should match | Custom mismatch message template. Supports placeholder replacement for {label_1} and {label_2}. |

Properties

| Property | Type | Description | | ------------------- | -------- | -------------------------------------------- | | validationMessage | string | Property equivalent of validation-message. |

Message Label Resolution

When replacing {label_1} and {label_2}, labels are resolved in this order:

  1. Associated <label for> text
  2. Wrapping <label> text
  3. aria-label
  4. name
  5. id

Examples

Email Verification

<form-matching-fields>
  <label for="email">Email</label>
  <input id="email" type="email" required />

  <label for="verify-email">Verify email</label>
  <input id="verify-email" type="email" required />
</form-matching-fields>

Custom Validation Message

<form-matching-fields
  validation-message="Please make sure {label_2} matches {label_1}."
>
  <label for="email">Email</label>
  <input id="email" type="email" required />

  <label for="verify-email">Verify email</label>
  <input id="verify-email" type="email" required />
</form-matching-fields>

Localized (Hindi) Message

<form-matching-fields
  validation-message="{label_1} और {label_2} का मान समान होना चाहिए।"
>
  <label for="password-hi">पासवर्ड</label>
  <input id="password-hi" type="password" required />

  <label for="password-hi-again">पासवर्ड फिर से</label>
  <input id="password-hi-again" type="password" required />
</form-matching-fields>

Browser Support

This component uses modern web standards:

  • Custom Elements v1
  • Shadow DOM v1
  • ES Modules

For older browsers, you may need polyfills.

Development

# Install dependencies
npm install

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Lint code
npm run lint

# Format code
npm run format

# View demo
open demo/index.html

License

MIT © Aaron Gustafson