Skip to content

Commit 770d1df

Browse files
authored
fix issue where validateWhenHidden was not validating for intentionally hidden components; add tests (#191)
1 parent 555beb3 commit 770d1df

2 files changed

Lines changed: 8 additions & 24 deletions

File tree

src/process/validation/index.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
ConditionsScope,
32
ProcessorFn,
43
ProcessorFnSync,
54
ProcessorInfo,
@@ -93,7 +92,10 @@ export function isForcedHidden(
9392
isConditionallyHidden: ConditionallyHidden,
9493
): boolean {
9594
const { component } = context;
96-
if (isConditionallyHidden(context as ConditionsContext)) {
95+
if (
96+
component.ephemeralState?.conditionallyHidden ||
97+
isConditionallyHidden(context as ConditionsContext)
98+
) {
9799
return true;
98100
}
99101
if (component.hasOwnProperty('hidden')) {
@@ -106,20 +108,8 @@ export const _shouldSkipValidation = (
106108
context: ValidationContext,
107109
isConditionallyHidden: ConditionallyHidden,
108110
) => {
109-
const { component, scope, path } = context;
110-
const absolutePath = getComponentAbsolutePath(component) || path;
111+
const { component } = context;
111112

112-
if (
113-
(scope as ConditionsScope)?.conditionals &&
114-
(find((scope as ConditionsScope).conditionals, {
115-
path: absolutePath,
116-
conditionallyHidden: true,
117-
}) ||
118-
component.ephemeralState?.conditionallyHidden === true)
119-
) {
120-
return true;
121-
}
122-
const { validateWhenHidden = false } = component || {};
123113
const rules = [
124114
// Skip validation if component is readOnly
125115
// () => this.options.readOnly,
@@ -128,7 +118,7 @@ export const _shouldSkipValidation = (
128118
// Check to see if we are editing and if so, check component persistence.
129119
() => isValueHidden(context),
130120
// Force valid if component is hidden.
131-
() => isForcedHidden(context, isConditionallyHidden) && !validateWhenHidden,
121+
() => !component.validateWhenHidden && isForcedHidden(context, isConditionallyHidden),
132122
];
133123

134124
return rules.some((pred) => pred());

src/process/validation/rules/validateRequired.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,9 @@ const valueIsPresent = (
7171
return true;
7272
};
7373

74-
export const shouldValidate = (context: ValidationContext) => {
74+
export const shouldValidate = (context: ValidationContext): boolean => {
7575
const { component } = context;
76-
if (
77-
component.validate?.required &&
78-
!(component.hidden || component.ephemeralState?.conditionallyHidden)
79-
) {
80-
return true;
81-
}
82-
return false;
76+
return !!component.validate?.required;
8377
};
8478

8579
export const validateRequired: RuleFn = async (context: ValidationContext) => {

0 commit comments

Comments
 (0)