feat: add event-driven validation plugin (SmarkForm.createValidation)#145
Draft
feat: add event-driven validation plugin (SmarkForm.createValidation)#145
SmarkForm.createValidation)#145Conversation
Agent-Logs-Url: https://github.com/bitifet/SmarkForm/sessions/77e71182-d446-4a5e-aef8-01c231a49ee5 Co-authored-by: bitifet <1643647+bitifet@users.noreply.github.com>
Agent-Logs-Url: https://github.com/bitifet/SmarkForm/sessions/77e71182-d446-4a5e-aef8-01c231a49ee5 Co-authored-by: bitifet <1643647+bitifet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add initial validation plugin for SmarkForm
feat: add event-driven validation plugin (Mar 31, 2026
SmarkForm.createValidation)
…n.md Agent-Logs-Url: https://github.com/bitifet/SmarkForm/sessions/26379dfe-783e-4717-b517-72ccb0056c93 Co-authored-by: bitifet <1643647+bitifet@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
## Complete Interactive Examplesection todocs/_advanced_concepts/validation.mdstart_date/end_dateper row), ➕/➖/▶ Export buttons,<ul id="msgs">message area,<pre id="out">export display.period-rowflex layout,[aria-invalid="true"]red border/background,.sf-issue.error/.warningstyled message items, scoped to#myForm$$checkDateOrderprovider (per-period date order),checkNoOverlapprovider (overlap detection between sorted periods),ValidationStateChangedhandler for inline messages,AfterAction_exporthandler for export outputsampletabs_tpl.mdinclude:showEditor=true,selected="preview",height=55,tests=falseValidationStateChangedvsValidationIssuesChanged* [Complete Interactive Example]Original prompt
Implement an initial, minimal validation plugin for SmarkForm, aligned with the library’s event-driven philosophy.
Repository: bitifet/SmarkForm
Goal
Create a first iteration of a validation system that can:
This is meant as a baseline to iterate on.
Design constraints / philosophy
changeevents (and potentially others) from the root.Functional requirements
1) Public API
Add a new module that exports something like:
createValidation(root, options)ornew SmarkValidation(root, options).validate(reason?)(force validation immediately)getState()(current issues, hasErrors/hasWarnings)destroy()(remove listeners)2) Provider interface
Providers should be passed in via options and have a uniform signature:
(ctx) => { issues } | Promise<{ issues }>{ root, data, reason, changedPaths?, signal? }.3) Issues model
Implement an Issue object with:
id(stable string)level: at leasterror|warningpaths: array of SmarkForm paths (at least one path)code,message,source(strings)details(optional)Implement default
idgeneration:${source}:${code}:${paths.join('|')}.4) Diffing
Store previous issues by id and compute:
(Optionally track changed issues, but not required for first iteration.)
5) Events emitted
Emit validation events through SmarkForm’s
.emitmechanism so they bubble (root-level).Proposed events:
ValidationStateChangedValidationIssuesChangedEach event should include the current issues and at least
newIssuesandsolvedIssues.Also implement a dedicated, preventable side-effect event:
BeforeValidationA11yApplyand/or allowValidationStateChangedto be preventable for ARIA application.6) ARIA side effects
By default:
aria-invalid="true"on targetFieldNode for any component path that currently has at least oneerrorissue.Warnings should not set aria-invalid.
Make this preventable via event cancelation so developers can override the behavior.
7) BeforeAction_export blocking
Hook into
BeforeAction_exporton the root:(Provide an option to disable this behavior.)
8) Documentation + example
Add minimal docs in
docs/_advanced_concepts/(or another appropriate place) describing:Optionally add a small docs example snippet that is included in the documentation testing framework.
9) Tests
Add at least a small Playwright test that:
Implementation notes
src/lib/validation/(or similar) and wire it into build.npm testpasses.Deliverables
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please review your AGENTS.md file and the rest of information you have under the AGENTS directory and then examine the codebase under the src directory to get a full understanding of how SmarkForm works and which is its philosophy.
You can also read the documentation under the docs directory for mor information.
When you have a full understanding on how everything works and how the library breaths, I want you to, following the same philosophy, propose a good and solid plan to approach form validation aids.
Our goal is to allow integration with common validation tools like zod taking in account both partial and full validation.
By partial, I mean if, for instance, we want to give feedbac...
This pull request was created from Copilot chat.