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 Nov 18, 2024
1 parent dd1d115 commit 5777d3d
Show file tree
Hide file tree
Showing 5 changed files with 554 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"dependencies": {
"@formio/bootstrap": "3.0.0-dev.98.17ba6ea",
"@formio/choices.js": "^10.2.1",
"@formio/core": "v2.1.0-dev.174.9a3c6ec",
"@formio/core": "2.1.0-dev.191.8c609ab",
"@formio/text-mask-addons": "^3.8.0-formio.3",
"@formio/vanilla-text-mask": "^5.1.1-formio.1",
"abortcontroller-polyfill": "^1.7.5",
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 @@ -3706,12 +3706,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 @@ -3722,7 +3716,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 5777d3d

Please sign in to comment.