Skip to content

Commit

Permalink
Merge branch 'master' of github.com:formio/core into adding-component…
Browse files Browse the repository at this point in the history
…-paths
  • Loading branch information
travist committed Nov 19, 2024
2 parents 7136546 + 770d1df commit 3106b9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
18 changes: 3 additions & 15 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 @@ -92,7 +91,7 @@ export function isForcedHidden(
isConditionallyHidden: ConditionallyHidden,
): boolean {
const { component } = context;
if (isConditionallyHidden(context as ConditionsContext)) {
if (component.scope?.conditionallyHidden || isConditionallyHidden(context as ConditionsContext)) {
return true;
}
if (component.hasOwnProperty('hidden')) {
Expand All @@ -105,19 +104,8 @@ export const _shouldSkipValidation = (
context: ValidationContext,
isConditionallyHidden: ConditionallyHidden,
) => {
const { component, scope, path } = context;
const { component } = context;

if (
(scope as ConditionsScope)?.conditionals &&
(find((scope as ConditionsScope).conditionals, {
path,
conditionallyHidden: true,
}) ||
component.scope?.conditionallyHidden === true)
) {
return true;
}
const { validateWhenHidden = false } = component || {};
const rules = [
// Skip validation if component is readOnly
// () => this.options.readOnly,
Expand All @@ -126,7 +114,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
7 changes: 2 additions & 5 deletions src/process/validation/rules/validateRequired.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +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.scope?.conditionallyHidden)) {
return true;
}
return false;
return !!component.validate?.required;
};

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

0 comments on commit 3106b9d

Please sign in to comment.