Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editor: fix can remove field when a hide expression exists #635

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
"markdown": "Hello **world**.\nGreat day.",
"array_with_multicheckbox": ["checkbox1", "checkbox2"],
"input_with_default_value": "slrofar6uh",
"enum": "val1"
"enum": "val1",
"notes": [
{
"type": "staff_note",
"content": "test"
}
]
},
"updated": "2024-03-06T07:47:33.944197+00:00"
}
102 changes: 102 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 @@ -7,9 +7,11 @@
"required"
],
"propertiesOrder": [
"notes",
"oneOf",
"optional",
"required",
"optional_hide_expression_field",
"essential",
"hidden",
"defaultHidden",
Expand Down Expand Up @@ -47,6 +49,91 @@
"field_radio_button_inline"
],
"properties": {
"notes": {
"title": "Notes",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"additionalProperties": false,
"title": "Note",
"propertiesOrder": [
"type",
"content"
],
"required": [
"type",
"content"
],
"properties": {
"type": {
"type": "string",
"title": "Type",
"enum": [
"staff_note",
"vendor_note"
],
"default": "staff_note",
"widget": {
"formlyConfig": {
"type": "selectWithSort",
"props": {
"options": [
{
"label": "vendor_note",
"value": "vendor_note"
},
{
"label": "staff_note",
"value": "staff_note"
}
]
}
}
}
},
"content": {
"type": "string",
"title": "Content",
"maxLength": 2000,
"minLength": 1,
"widget": {
"formlyConfig": {
"type": "textarea",
"props": {
"rows": 3
}
}
}
}
}
},
"widget": {
"formlyConfig": {
"wrappers": [
"card"
],
"props": {
"validation": {
"validators": {
"uniqueValueKeysInObject": {
"keys": [
"type"
]
}
},
"messages": {
"uniqueValueKeysInObjectMessage": "Only one note per type is allowed"
}
},
"hide": true,
"navigation": {
"essential": true
}
}
}
}
},
"$schema": {
"title": "Schema",
"type": "string",
Expand Down Expand Up @@ -251,6 +338,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
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ export class AddFieldEditorComponent implements OnInit {
* @param match - TypeaheadMath, the selected element
*/
showSelectedField(field: any) {
// show the field in the form
field.hide = false;
// reset the input value
this.value = undefined;
// remove the the element from the list of hidden fields
Expand All @@ -164,6 +162,8 @@ export class AddFieldEditorComponent implements OnInit {
// See: https://blog.angular-university.io/angular-debugging/
// wait that the component is present in the DOM
setTimeout(() => this.editorComponentInstance.setFieldFocus(field, true));
// show the field in the form
field.hide = false;
}

/**
Expand Down