Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-9329: fix issue where validateWhenHidden now validates hidden and conditionally hidden components #191

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions src/process/validation/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ConditionsScope,
ProcessorFn,
ProcessorFnSync,
ProcessorInfo,
Expand Down Expand Up @@ -93,7 +92,10 @@ export function isForcedHidden(
isConditionallyHidden: ConditionallyHidden,
): boolean {
const { component } = context;
if (isConditionallyHidden(context as ConditionsContext)) {
if (
component.ephemeralState?.conditionallyHidden ||
isConditionallyHidden(context as ConditionsContext)
) {
return true;
}
if (component.hasOwnProperty('hidden')) {
Expand All @@ -106,20 +108,8 @@ export const _shouldSkipValidation = (
context: ValidationContext,
isConditionallyHidden: ConditionallyHidden,
) => {
const { component, scope, path } = context;
const absolutePath = getComponentAbsolutePath(component) || path;
const { component } = context;

if (
(scope as ConditionsScope)?.conditionals &&
(find((scope as ConditionsScope).conditionals, {
path: absolutePath,
conditionallyHidden: true,
}) ||
component.ephemeralState?.conditionallyHidden === true)
) {
return true;
}
const { validateWhenHidden = false } = component || {};
const rules = [
// Skip validation if component is readOnly
// () => this.options.readOnly,
Expand All @@ -128,7 +118,7 @@ export const _shouldSkipValidation = (
// Check to see if we are editing and if so, check component persistence.
() => isValueHidden(context),
// Force valid if component is hidden.
() => isForcedHidden(context, isConditionallyHidden) && !validateWhenHidden,
() => !component.validateWhenHidden && isForcedHidden(context, isConditionallyHidden),
];

return rules.some((pred) => pred());
Expand Down
10 changes: 2 additions & 8 deletions src/process/validation/rules/validateRequired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,9 @@ const valueIsPresent = (
return true;
};

export const shouldValidate = (context: ValidationContext) => {
export const shouldValidate = (context: ValidationContext): boolean => {
const { component } = context;
if (
component.validate?.required &&
!(component.hidden || component.ephemeralState?.conditionallyHidden)
) {
return true;
}
return false;
return !!component.validate?.required;
};

export const validateRequired: RuleFn = async (context: ValidationContext) => {
Expand Down
Loading