Skip to content

Commit

Permalink
FIO-9329: validateWhenHidden respects both conditionally hidden and i…
Browse files Browse the repository at this point in the history
…ntentionally hidden (#5906)

* validateWhenHidden respects all kinds of visibility

* add clearOnHide: false to fix test
  • Loading branch information
brendanbond authored and lane-formio committed Nov 18, 2024
1 parent aeea012 commit 653c21b
Show file tree
Hide file tree
Showing 5 changed files with 555 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased: 5.0.0-rc.99]
### Changed
- FIO-9329: validateWhenHidden respects both conditionally hidden and intentionally hidden

## 5.0.0-rc.98
### Changed
- FIO-9280 fixed validation for select boxes with valid values and when value property is not set
Expand Down
15 changes: 8 additions & 7 deletions src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3678,12 +3678,6 @@ export default class Component extends Element {
}

shouldSkipValidation(data, row, flags = {}) {
const { validateWhenHidden = false } = this.component || {};
const forceValidOnHidden = (!this.visible || !this.checkCondition(row, data)) && !validateWhenHidden;
if (forceValidOnHidden) {
// If this component is forced valid when it is hidden, then we also need to reset the errors for this component.
this._errors = [];
}
const rules = [
// Do not validate if the flags say not too.
() => flags.noValidate,
Expand All @@ -3694,7 +3688,14 @@ export default class Component extends Element {
// Check to see if we are editing and if so, check component persistence.
() => this.isValueHidden(),
// Force valid if component is hidden.
() => forceValidOnHidden
() => {
if (!this.component.validateWhenHidden && (!this.visible || !this.checkCondition(row, data))) {
// If this component is forced valid when it is hidden, then we also need to reset the errors for this component.
this._errors = [];
return true;
}
return false;
}
];

return rules.some(pred => pred());
Expand Down
Loading

0 comments on commit 653c21b

Please sign in to comment.