Repository navigation
feat: expose the Form Validator in the React, Angular and Vue bindings - #2646
Draft
gigibiffi84 wants to merge 4 commits into
Draft
gigibiffi84 wants to merge 4 commits into
gigibiffi84 wants to merge 4 commits into
Conversation
✅ Deploy Preview for jsonforms-examples ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
gigibiffi84
added a commit
to gigibiffi84/jsonforms
that referenced
this pull request
Oct 18, 2026
Brings feat/form-validator-bridge-v2 (the eclipsesource#2644 rework on current upstream master) into fork master and ports the stacked work to the new API: - core: `state.validator` holds the Form Validator, the custom factory is kept in `state.validatorFactory`; no default Ajv instance is created while a factory is set (eclipsesource#2648). - rules (eclipsesource#2645): conditions are evaluated with the validator factory (one cached Form Validator per condition schema) or the Ajv instance; `matches` and the bound-validator branch are gone. `getRuleValidator` reads `validatorFactory ?? ajv`. - bindings (eclipsesource#2646): the `validator` prop of React, Vue and Angular is a FormValidatorFactory; `useValidator` reads `state.validator`. - standard-schema: `fromStandardSchema` returns a factory. For its own JSON Schema it validates with the library and sets `parentSchema` per issue (`schemaAt`, moved here from core); for other schemas, e.g. rule conditions, it uses core's schema matcher. No `severity`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B36yeVG6EUUhwMCEzybGEH
gigibiffi84
marked this pull request as draft
October 18, 2026 15:04
gigibiffi84
force-pushed
the
feat/validator-prop-bindings
branch
from
October 18, 2026 15:48
f2acbc0 to
e455d36
Compare
Contributor
Author
|
Rebased onto the reworked #2644 for context, see the overview there: #2644 (comment). Still a draft until #2644 is accepted. |
Adds a `validator` init/updateCore option taking a factory `(schema) => FormValidator`. Core calls it whenever the schema changes and stores the result in `state.validator`; without the option, Ajv is the default Form Validator via `createAjvValidator`. Like the other options, `validator: undefined` keeps the current value. - `FormValidator.validate(data)` returns `ValidationIssue`s, which `issuesToErrors` converts to the Ajv error objects stored in the state. A missing `key` becomes `custom`; a `required` issue addressed to the missing property is split into parent path plus `params.missingProperty`. Ajv errors round-trip unchanged. - `compiledAjvValidator(validateFn)` wraps an already compiled Ajv function, e.g. generated via Ajv standalone code. - `getValidator(state)` exposes the current Form Validator. - Switching to NoValidation via setValidationMode now also drops the validator, so later data updates no longer reintroduce errors. `JsonFormsCore.validator` changes from the compiled Ajv function to a Form Validator, see MIGRATION.md. Part of eclipsesource#1498 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B36yeVG6EUUhwMCEzybGEH
…ing them with Ajv Combinator tab selection compiled every oneOf/anyOf/allOf branch with Ajv and then ignored all errors except the structural keywords required, additionalProperties, type, enum and const. The new isStructuralMatch evaluates exactly those keywords itself, recursively through properties, patternProperties, items, $ref, nested combinators and if/then/else. Tab selection therefore no longer depends on an Ajv instance or on code generation, so it also works under a Content Security Policy without unsafe-eval. Equivalence with the previous filtered-Ajv behaviour is covered by tests comparing both approaches keyword by keyword. Part of eclipsesource#1498 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Schema based rule conditions were always evaluated with ajv.validate(condition.schema, value), the last place where a custom Form Validator did not apply. - Widen the `ajv` parameter of isVisible, isEnabled, isReadonly, the eval* functions and Runtime.isVisible/isEnabled to RuleValidator: an Ajv instance (unchanged behaviour), a FormValidatorFactory (one Form Validator per condition schema, cached) or undefined (the Structural Matcher). - Add matchesConditionSchema and the getRuleValidator selector (`validatorFactory`, otherwise `ajv`); core's own mappers pass getRuleValidator(state) instead of getAjv(state). Part of eclipsesource#1498 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B36yeVG6EUUhwMCEzybGEH
- React, Vue and Angular JsonForms gain a `validator` prop/input next to `ajv`, a FormValidatorFactory forwarded to init/updateCore; Vue adds useValidator(); JsonFormsAngularService.updateCoreState takes an optional validator. - Material and vanilla withAjvProps additionally inject `ruleValidator` (getRuleValidator), used by the categorization layouts; Angular Material evaluates category visibility with getRuleValidator too. - ExampleDescription gains an optional `validator`, passed through by all five example apps; new "Custom validator" example with a dependency-free handwritten Form Validator. Its factory validates the form schema by hand and other schemas, such as the rule condition, with the Structural Matcher. Part of eclipsesource#1498 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B36yeVG6EUUhwMCEzybGEH
gigibiffi84
force-pushed
the
feat/validator-prop-bindings
branch
from
October 18, 2026 16:34
e455d36 to
4c9d617
Compare
This branch has not been deployed
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.
Part of #1498. Stacked on #2644 (Form Validator) and #2645 (rules through the Form Validator); the diff shrinks to the last commit once those are merged.
What changed
The bindings expose the core
validatoroption and the renderer sets evaluate rules through it.JsonForms: newvalidator?: FormValidatorFactoryprop next toajv, forwarded toinit/updateCore.JsonForms: newvalidatorprop, forwarded toinit/updateCoreand watched likeajv; newuseValidator()returningstate.validator, mirroringuseAjv().JsonForms: new@Input() validator;JsonFormsAngularService.updateCoreStatetakes an optionalvalidatorargument (defaults to keeping the stored one).withAjvProps(material and vanilla) additionally injectsruleValidatorfromgetRuleValidator; the categorization layouts evaluate category visibility with it.mapStateToVisibleusegetRuleValidator(state)instead ofgetAjv(state).ExampleDescriptiongains an optionalvalidator, passed by all five example apps. New "Custom validator" example with a dependency-free, handwritten Form Validator. Its factory validates the form schema by hand and other schemas, such as its rule condition, with the Structural Matcher.For adopters
Nothing changes without the new prop;
ajvkeeps working everywhere. Known gap, left for a follow-up: vue-vuetify'sAdditionalPropertiespasses onlyajvto its nested form, so a nested form under a custom validator still validates with Ajv.Tests
JsonForms.test.tsxcase asserting the factory reaches core and its issue renders as the control's error. React tests green (36).JsonForms.spec.tscase asserting the factory reaches core and its issue is stored as an error. Vue tests green (25).🤖 Generated with Claude Code