Skip to content

Commit

Permalink
ON-43900 # Evaluate predicates and disable form submission based on `…
Browse files Browse the repository at this point in the history
…enableSubmission` form property
  • Loading branch information
RyanButton committed Oct 1, 2024
1 parent 6822ce5 commit 6835970
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Evaluate predicates and disable form submission based on `enableSubmission` form property

## [6.7.0] - 2024-09-30

### Changed
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/OneBlinkFormBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,11 @@ function OneBlinkFormBase({
//
// #region Conditional Logic

const { formElementsConditionallyShown, conditionalLogicError } =
useConditionalLogic(definition, submission)
const {
formElementsConditionallyShown,
conditionalLogicError,
submissionConditionallyEnabled,
} = useConditionalLogic(definition, submission)

// #endregion
//
Expand Down Expand Up @@ -1228,7 +1231,10 @@ function OneBlinkFormBase({
{ 'is-loading': isPreparingToSubmit },
)}
disabled={
isPreview || disabled || isPreparingToSubmit
isPreview ||
disabled ||
isPreparingToSubmit ||
!submissionConditionallyEnabled
}
>
<CustomisableButtonInner
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/useConditionalLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,24 @@ export default function useConditionalLogic(
})
}, [definition.elements, submission, errorCallback])

const submissionConditionallyEnabled = React.useMemo(() => {
if (!definition.enableSubmission) {
return true
}
const { requiresAllConditionalPredicates, conditionalPredicates } =
definition.enableSubmission
return conditionalLogicService.evaluateConditionalPredicates({
isConditional: true,
requiresAllConditionalPredicates,
conditionalPredicates,
formElements: definition.elements,
submission,
})
}, [definition.elements, definition.enableSubmission, submission])

return {
conditionalLogicError,
formElementsConditionallyShown,
submissionConditionallyEnabled,
}
}

0 comments on commit 6835970

Please sign in to comment.