Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f4f45f0
Convert to pnpm, update deps to latest, add wire size script
jdlien Jan 23, 2026
82dadc1
Bump version to 2.0.0 and add CLAUDE.md
jdlien Jan 23, 2026
a20a43c
Implement v2.0.0 features: performance optimizations, type safety, an…
jdlien Jan 23, 2026
5679774
Update documentation for v2.0.0 features
jdlien Jan 23, 2026
5c2f587
Add tests to improve branch coverage
jdlien Jan 23, 2026
f68d6f6
Fix select dropdown chevron styling and update to Tailwind v4 syntax
jdlien Jan 23, 2026
2444c1c
Add form-field custom element to reduce demo boilerplate
jdlien Jan 23, 2026
c55e7f3
Refactor form-field custom element to TypeScript with DOM API
jdlien Jan 23, 2026
f4cb975
Fix CSS attribute selectors to only target input elements
jdlien Jan 23, 2026
cbffc8c
Add compiled form-field.js for static server compatibility
jdlien Jan 23, 2026
7858e5f
Fix checked-border/checked-label to use regular classes instead of @u…
jdlien Jan 23, 2026
4d9a668
Add build:demo script to compile form-field.ts and CSS
jdlien Jan 23, 2026
df71d0b
Fix radio button focus ring and update demo theme to indigo
jdlien Jan 23, 2026
c60c138
Use local tailwindcss CLI instead of npx to avoid npm warnings
jdlien Jan 23, 2026
90e6864
Add watch:css script for development
jdlien Jan 23, 2026
9898a1b
Fix radio focus ring to use box-shadow (follows border-radius unlike …
jdlien Jan 23, 2026
bbce65b
Add scrollToErrorDelay option and improve demo form styling
jdlien Jan 24, 2026
1ea7a94
Fix select/textarea change handler and improve demo styling
jdlien Jan 24, 2026
47c0139
Add Vite HMR support for demo development
jdlien Jan 24, 2026
fb603f0
Add form section cards and tweak demo text contrast
jdlien Jan 24, 2026
51e0ccf
Refine demo submit button styling
jdlien Jan 24, 2026
aca9d7f
Add configurable dark mode toggle
jdlien Jan 24, 2026
bd5d2f6
Automate demo build outputs
jdlien Jan 24, 2026
743cb10
Add demo/*.js to gitignore
jdlien Jan 24, 2026
1f7437f
Add arrow key increment/decrement for number fields
jdlien Jan 24, 2026
1bc9363
Style tweaks to text on demo
jdlien Jan 24, 2026
48e527b
Remove MutationObserver-based auto re-init and auto-destroy
jdlien Jan 24, 2026
2a64b0b
Consolidate v2.0.0 changelog with accurate bundle sizes
jdlien Jan 24, 2026
54b9626
Fix 6 bugs and improve code efficiency
jdlien Jan 25, 2026
bfc76e6
Add bug fixes to v2.0.0 changelog
jdlien Jan 25, 2026
27329db
Remove superfluous details
jdlien Jan 25, 2026
88a37f6
Add multi-format build output (ESM, CJS, UMD)
jdlien Jan 25, 2026
68bdbfb
Add validateOnBlur option for blur event validation
jdlien Jan 25, 2026
704329b
Fix index.ts coverage by using intermediate export variable
jdlien Jan 25, 2026
0230491
Add CI workflow and ISC license
jdlien Jan 25, 2026
6dd1422
Add validateSingle method for programmatic single-input validation
jdlien Jan 25, 2026
b0b309e
Add file input validation with size, count, and type constraints
jdlien Jan 25, 2026
ecb2f88
Add human-readable file size parsing and decimal formatting
jdlien Jan 25, 2026
f3b0e22
Fix file validation attributes not passed through form-field component
jdlien Jan 25, 2026
607cdda
Add binary units, fail-closed parsing, and boundary rounding for file…
jdlien Jan 26, 2026
5c9724f
Update test setup and lockfile for validator-utils v2.0.0
jdlien Jan 26, 2026
99258b7
Add custom validation examples and sidebar navigation to demo
jdlien Jan 26, 2026
12e9488
Add hybrid validator registry and form-card component
jdlien Jan 27, 2026
5418807
feat: style tweaks for form elements
jdlien Jan 27, 2026
8f3e608
feat: style tweaks for cards
jdlien Jan 27, 2026
d85037c
style: use semantic tags
jdlien Jan 27, 2026
94ffd74
fix: max-w classes
jdlien Jan 27, 2026
703e3ce
feat: style tweaks to demo form
jdlien Jan 27, 2026
b53b5ec
Fix group selection error clearing
jdlien Jan 27, 2026
db7e3e6
feat: add static validation methods for standalone inputs
jdlien Jan 27, 2026
750a469
Add console warning for validateSingle on input not in form
jdlien Jan 27, 2026
4815216
docs: list ESM before UMD as recommended option
jdlien Jan 27, 2026
ab3750c
fix: float and decimal type validation was broken
jdlien Jan 27, 2026
97f2355
docs: updated docs for completeness
jdlien Jan 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10.11.0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install canvas system dependencies
run: sudo apt-get update && sudo apt-get install -y libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
- run: pnpm install --frozen-lockfile
- run: pnpm test
- run: pnpm build:lib
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ lerna-debug.log*
package-lock.json
coverage
demo.css
demo/*.js

node_modules
.pnpm-store
dist
dist-ssr
*.local
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"trailingComma": "es5",
"semi": false,
"singleQuote": true,
"printWidth": 100
"printWidth": 100,
"plugins": ["prettier-plugin-tailwindcss"]
}
99 changes: 98 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,103 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0] - 2026-01-26

Major new release with many different features and fixes. Now depends on v2.1 of `@jdlien/validator-utils`. The bundle size has increased slightly (~1.5KB zipped), but there are lots of new features to make the size well worth it!

### Bundle Size

| | v1.5.0 | v2.0.0 | Change |
| ------ | --------- | --------- | ------- |
| Raw | 21.60 KiB | 27.24 KiB | +26.1% |
| Gzip | 7.40 KiB | 8.85 KiB | +19.6% |
| Brotli | 6.59 KiB | 7.90 KiB | +19.9% |

### Added
- **Hybrid Validator Registry System**: Three-tier validator lookup (instance → static → window)
- `validators` option in constructor for instance-scoped validators (highest priority)
- `Validator.registerValidator(name, fn)` for global validators shared across instances
- `Validator.unregisterValidator(name)` to remove a global validator
- `Validator.getValidators()` returns a copy of all global validators
- `Validator.clearValidators()` removes all global validators
- `validateSingle(input)` instance method for programmatic single-input validation on demand
- **Static methods for standalone validation** (inputs outside forms):
- `Validator.validateSingle(input, options?)` - validates any input without needing an instance
- `Validator.clearInputErrors(input, options?)` - clears errors from any input without an instance
- `clearInputErrors(input)` instance method to clear errors from a specific input
- `clearAllErrors()` instance method to clear all form errors
- `scrollToError` option to scroll to first invalid input on validation failure
- `scrollToErrorDelay` option to delay scroll-to-error behavior (useful for animations)
- Min/max value validation via `data-min`/`data-max` attributes (also respects native `min`/`max`)
- `ERROR_MIN_VALUE` and `ERROR_MAX_VALUE` error messages
- `ValidationEvent` unified event class with `ValidationEventType` type
- Arrow key increment/decrement for `number`, `float`, and `decimal` fields (previously only `integer`)
- `data-arrow-step` attribute to customize arrow key step size (e.g., `data-arrow-step="0.5"`)
- Set `data-arrow-step=""` (empty string) to disable arrow key behavior on numeric fields
- Arrow keys respect `data-min`/`data-max` bounds, clamping values appropriately
- `validateOnBlur` option to validate fields when they lose focus (even if unchanged)
- New type exports: `ValidatorFunction`, `ValidationResult`, `ValidatorRegistry`

### Changed

- `messages` option now typed as `Record<string, string>` (was `object`)
- Integer fields now respect `data-min` for negative values (previously hardcoded to min 0)
- `validateSingle(input)` instance method now only validates inputs belonging to its form (use static `Validator.validateSingle()` for standalone inputs)
- Package exports now include explicit ESM/CJS entry points (UMD still available at `dist/validator.js`)
- Custom validation now uses three-tier lookup: instance registry → static registry → window object
- Demo page updated to use instance registry instead of window functions

### Removed

- `types.d.ts` file (duplicated Validator.ts exports)
- `ValidationSuccessEvent` class (use `ValidationEvent` with type `'validationSuccess'`)
- `ValidationErrorEvent` class (use `ValidationEvent` with type `'validationError'`)
- Automatic MutationObserver-based re-init and auto-destroy (see Breaking Changes)

### Fixed

- Color sync no longer throws when a `type="color"` input has no paired text input
- Custom error messages now apply to type validators (number, email, tel, etc.)
- Error classes on inputs are now removed even when no error element exists
- Stale `inputErrors` entries are cleared when `init()` is called after removing inputs
- Pattern validation no longer throws for invalid regex patterns (treats as pass-through)
- Pattern validation now anchors patterns for full-match behavior (matches HTML5 `pattern` attribute)
- Error border colors on required multi-check/radio inputs are now cleared when any related input is checked

### Breaking Changes

- **Manual reinitialized required after DOM changes:** Previously, Validator would attempt to reinitialize itself if form elements were added or changed in the DOM using a mutationObserver, but this was inefficient and unreliable and was mostly handling niche cases. If you add/remove inputs dynamically, call `validator.init()` after DOM updates.
- **Manual cleanup now required when removing forms:** Previously, Validator would attempt to detect if the form were removed and clean itself up. This could be useful in an SPA or a modal dialog that loads different forms to keep accumulating Validator instances. This is considered an edge-case so Validator no longer handles this itself. Now, if you remove a form from the DOM, call `validator.destroy()` before removing it.
- **Event classes consolidated:** Replace `ValidationSuccessEvent` and `ValidationErrorEvent` with unified `ValidationEvent` class

```typescript
// Before
form.addEventListener('validationSuccess', (e: ValidationSuccessEvent) => { ... })

// After
form.addEventListener('validationSuccess', (e: ValidationEvent) => { ... })
```

- **`messages` typing:** Now `Record<string, string>` instead of `object`
- **`types.d.ts` removed:** Import types from `Validator.ts` instead


### Migration Guide

No breaking changes. Existing code using window functions continues to work. To migrate:

```javascript
// Before (still works)
window.myValidator = (value) => value.length > 3

// After (recommended)
const validator = new Validator(form, {
validators: {
myValidator: (value) => value.length > 3,
},
})
```

## [1.5.0] - 2025-01-08

### Added
Expand All @@ -16,7 +113,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
### Changed

- **BREAKING CHANGE**: Removed ineffective 'remove' event listener and replaced with robust MutationObserver-based cleanup
- Enhanced `destroy()` method to properly clean up both `formMutationObserver` and `autoDestroyObserver`
- Enhanced `destroy()` method to properly clean up both `formMutationObserver` and `autoDestroyObserver`
- Simplified test files by removing manual `validator.destroy()` calls from all `afterEach` blocks - auto-destroy now handles cleanup
- Updated event listener tests to reflect removal of 'remove' event listener (4 listeners instead of 5)
- Improved TypeScript null assertion handling with proper `!` operators
Expand Down
16 changes: 16 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Validator

This is a utility that can add user friendly, accessible validation to forms using native HTML attributes that is easy to use and powerful.

This project has the following goals:

1. Compactness and efficiency above all else.
2. 100% test coverage of all functionality, with a broad corpus of tests to evaluate behavior of a wide range of acceptable inputs, especially for dates.
3. Focus on high-value functionality, carefully consider whether adding new functionality is highly impactful and reusable in many projects.

When completed edits or new features:

1. Ensure that all tests run with 100% coverage
`pnpm coverage`
2. Compare the original size with the new size. Have we been able to keep the wire size as small or better than before? If the size has increased meaningfully, notify the user.
`pnpm size:wire`
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ISC License

Copyright (c) 2026 JD Lien

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Loading