Skip to content

Commit

Permalink
editor: fix can remove field when a hide expression exists
Browse files Browse the repository at this point in the history
* Avoids the possiblity to remove or add a field with an hide expression (tash button on the label component).
* Adds an exemple in the demo editor.
* Does not add a field with an hide expression during the edit initialization. In the previous versions the field was in the editor and in the completion menu.

Co-Authored-by: Johnny Mariéthoz <[email protected]>
  • Loading branch information
jma committed Jul 25, 2024
1 parent 3a0bc78 commit 2e53c6c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions projects/ng-core-tester/src/app/record/editor/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"oneOf",
"optional",
"required",
"optional_hide_expression_field",
"essential",
"hidden",
"defaultHidden",
Expand Down Expand Up @@ -251,6 +252,21 @@
}
}
},
"optional_hide_expression_field": {
"title": "Optional Field with Hide Expression",
"type": "string",
"minLength": 3,
"widget": {
"formlyConfig": {
"expressions": {
"hide": "!field.parent.model.required"
},
"props": {
"doNotSubmitOnEnter": true
}
}
}
},
"enum": {
"title": "List of values",
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,8 @@ export class EditorComponent extends AbstractCanDeactivateComponent implements O
}
return (
!field.props.required &&
!field.hide
!field.hide &&
!('hide' in field?.expressions)
);
}

Expand Down
2 changes: 2 additions & 0 deletions projects/rero/ng-core/src/lib/record/editor/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export class NgCoreFormlyExtension {
// ignore array item which as key of the form "0"
// TODO: find a better way to identify this case
|| !isNaN(Number(field.key))
// ignore field that has hide expression
|| ('hide' in field?.expressions)
// do not hide a field containing a 'hide' wrapper
|| this._hasHideWrapper(field)
// do not hide a field that has a parent marked as hidden and a model is empty
Expand Down

0 comments on commit 2e53c6c

Please sign in to comment.