From f2cbd02bc4052ce7d5092326a251dd701a36b558 Mon Sep 17 00:00:00 2001 From: eyelidlessness Date: Wed, 10 Jul 2024 14:49:36 -0700 Subject: [PATCH] Fix (engine): skip validation of non-relevant nodes Note: no change to aggregation necessary! Derived state is awesome. --- .../src/instance/internal-api/ValidationContext.ts | 1 + .../src/lib/reactivity/validation/createValidation.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/xforms-engine/src/instance/internal-api/ValidationContext.ts b/packages/xforms-engine/src/instance/internal-api/ValidationContext.ts index 89f461dc..ffaa8606 100644 --- a/packages/xforms-engine/src/instance/internal-api/ValidationContext.ts +++ b/packages/xforms-engine/src/instance/internal-api/ValidationContext.ts @@ -17,6 +17,7 @@ interface ValidationContextDefinition { export interface ValidationContext extends EvaluationContext, SubscribableDependency { readonly definition: ValidationContextDefinition; + isRelevant(): boolean; isRequired(): boolean; isBlank(): boolean; } diff --git a/packages/xforms-engine/src/lib/reactivity/validation/createValidation.ts b/packages/xforms-engine/src/lib/reactivity/validation/createValidation.ts index ada00a9c..7be87a06 100644 --- a/packages/xforms-engine/src/lib/reactivity/validation/createValidation.ts +++ b/packages/xforms-engine/src/lib/reactivity/validation/createValidation.ts @@ -81,7 +81,7 @@ const createConstraintValidation = ( const message = createViolationMessage(context, 'constraintMsg', constraintMsg); return createMemo(() => { - if (context.isBlank() || isValid()) { + if (!context.isRelevant() || context.isBlank() || isValid()) { return constraintValid(); } @@ -123,7 +123,7 @@ const createRequiredValidation = ( const message = createViolationMessage(context, 'requiredMsg', requiredMsg); return createMemo(() => { - if (isValid()) { + if (!context.isRelevant() || isValid()) { return requiredValid(); }