feat(formplayer): Enable AJV $data cross-field validation & computed fields engine
#302
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.
Description
Adds two core capabilities to the formplayer and formulus extension pipeline:
Closes #304
$datacross-field validation: AJV now supports$datareferences, enabling schema rules like{"const": {"$data": "1/otherField"}}to validate that one field matches another.ext.json. The formplayer watches dependencies, calls the registered extension function, and updates the field value automatically.Why
$datarules enforce this in the schema with a clear error message no custom code needed per form.2-2-4-A(region-sector-ponto-household) must be computed from multiple fields. The computed fields engine lets apps define this logic inext.json+ a helper JS module, keeping the formplayer generic.Changes
formulus-formplayer (6 files):
App.tsx: Enable$data: truein AJV; exposewindow.formulusCurrentFormData; add computed fields processing inhandleDataChangeExtensionsLoader.ts: AddcomputedFieldsto metadata and load result interfacesFormulusInterfaceDefinition.ts: AddcomputedFieldstoExtensionMetadataFormEvaluationContext.tsx: Export sharedExtensionFunctiontypebuiltinExtensions.ts: Use shared type, fix lint issuesDynamicEnumControl.tsx: Fix lint warnings, apply prettierformulus (2 files):
ExtensionService.ts: AddcomputedFieldsto interfaces; pass through fromext.json; deep merge by formType; fix pre-existing type errorsFormplayerModal.tsx: IncludecomputedFieldsin the extensions object sent to the formplayer WebViewHow apps use it
$datavalidation inschema.json:{ "const": { "$data": "1/qr_captura" } }Computed fields in
ext.json:The function is a standard extension function loaded from a JS module. It receives the full form data and returns the computed value.