@if (showError && formControl.errors) {
diff --git a/projects/rero/ng-core/src/lib/record/editor/widgets/add-field-editor/add-field-editor.component.ts b/projects/rero/ng-core/src/lib/record/editor/widgets/add-field-editor/add-field-editor.component.ts
index 6ac4c071..3d273505 100644
--- a/projects/rero/ng-core/src/lib/record/editor/widgets/add-field-editor/add-field-editor.component.ts
+++ b/projects/rero/ng-core/src/lib/record/editor/widgets/add-field-editor/add-field-editor.component.ts
@@ -153,17 +153,8 @@ 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
- this.editorComponentInstance.removeHiddenField(field);
- // scroll at the right position
- // to avoid: Expression has changed after it was checked
- // See: https://blog.angular-university.io/angular-debugging/
- // wait that the component is present in the DOM
- setTimeout(() => this.editorComponentInstance.setFieldFocus(field, true));
+ this.editorComponentInstance.setHide(field, false);
+ this.value = null;
}
/**
diff --git a/projects/rero/ng-core/src/lib/record/editor/widgets/label/label.component.ts b/projects/rero/ng-core/src/lib/record/editor/widgets/label/label.component.ts
index b319bca0..b64c65fe 100644
--- a/projects/rero/ng-core/src/lib/record/editor/widgets/label/label.component.ts
+++ b/projects/rero/ng-core/src/lib/record/editor/widgets/label/label.component.ts
@@ -15,36 +15,25 @@
* along with this program. If not, see .
*/
-import { Component, Input, OnInit } from '@angular/core';
+import { Component, Input } from '@angular/core';
import { FormlyFieldConfig } from '@ngx-formly/core';
import { TranslateService } from '@ngx-translate/core';
-import { EditorComponent } from '../../editor.component';
@Component({
selector: 'ng-core-label-editor',
templateUrl: './label.component.html',
})
-export class LabelComponent implements OnInit {
+export class LabelComponent {
// Current field
@Input() field: FormlyFieldConfig;
- // Instance of Editor Component
- private editorComponentInstance?: EditorComponent;
-
/**
* Constructor
* @param translateService - TranslateService, that translate the labels of the hidden fields
*/
constructor(private translateService: TranslateService) {}
- /** onInit hook */
- ngOnInit(): void {
- if (this.field.props.editorComponent) {
- this.editorComponentInstance = (this.field.props.editorComponent)();
- }
- }
-
/**
* Is the dropdown menu displayed?
* @param field - FormlyFieldConfig, the corresponding form field config
@@ -59,7 +48,7 @@ export class LabelComponent implements OnInit {
}
return (
(this.hiddenFieldGroup(this.getFieldGroup(this.field)).length > 0 ||
- this.field.props.helpURL) && this.editorComponentInstance?.longMode
+ this.field.props.helpURL) && field.props.editorConfig.longMode
);
}
@@ -124,7 +113,7 @@ export class LabelComponent implements OnInit {
* @returns boolean, true if I'm the root
*/
isRoot(): boolean {
- return this.editorComponentInstance ? this.editorComponentInstance.isRoot(this.field) : false;
+ return this.field.props?.isRoot || false;
}
/**
@@ -132,8 +121,8 @@ export class LabelComponent implements OnInit {
* @param field - FormlyFieldConfig, the field to hide
*/
remove(): void {
- if (this.field.parent.type === 'object' && this.editorComponentInstance) {
- this.editorComponentInstance.hide(this.field);
+ if (this.field.parent.type === 'object') {
+ this.field.props.setHide ? this.field.props.setHide(this.field, true): this.field.hide = true;
}
if (this.field.parent.type === 'array') {
this.field.parent.props.remove(this.getIndex());
@@ -145,7 +134,7 @@ export class LabelComponent implements OnInit {
* @param field - FormlyFieldConfig, the field to show
*/
show(field: FormlyFieldConfig) {
- field.hide = false;
+ this.field.props.setHide ? this.field.props.setHide(this.field, false): this.field.hide = false;
}
/**
@@ -153,13 +142,20 @@ export class LabelComponent implements OnInit {
* @returns boolean, true if the field can be hidden
*/
canRemove(): boolean {
- if (this.field.parent.type === 'object') {
- return this.editorComponentInstance ? this.editorComponentInstance.canHide(this.field) : false;
- }
- if (this.field.parent.type === 'array') {
- return this.field.parent.props.canRemove();
- }
- return false;
+ switch (this.field.parent.type) {
+ case 'object':
+ if (!this.field.props.editorConfig.longMode) {
+ return false;
+ }
+ return (
+ !this.field.props.required &&
+ !this.field.hide
+ );
+ case 'array':
+ return this.field.parent.props.canRemove();
+ default:
+ return false;
+ }
}
/**
diff --git a/projects/rero/ng-core/src/lib/record/editor/wrappers/form-field-wrapper/form-field-wrapper.component.ts b/projects/rero/ng-core/src/lib/record/editor/wrappers/form-field-wrapper/form-field-wrapper.component.ts
index c01e3080..3fad2882 100644
--- a/projects/rero/ng-core/src/lib/record/editor/wrappers/form-field-wrapper/form-field-wrapper.component.ts
+++ b/projects/rero/ng-core/src/lib/record/editor/wrappers/form-field-wrapper/form-field-wrapper.component.ts
@@ -14,9 +14,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
+import { ChangeDetectionStrategy, Component } from '@angular/core';
import { FieldWrapper } from '@ngx-formly/core';
-import { EditorComponent } from '../../editor.component';
@Component({
selector: 'ng-core-form-field-wrapper',
@@ -54,23 +53,13 @@ import { EditorComponent } from '../../editor.component';
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
-export class FormFieldWrapperComponent extends FieldWrapper implements OnInit {
-
- private editorComponentInstance?: EditorComponent = null;
-
- ngOnInit(): void {
- if (this.field?.props?.editorComponent) {
- this.editorComponentInstance = (this.field.props.editorComponent)();
- }
- }
+export class FormFieldWrapperComponent extends FieldWrapper {
/** Hide the field */
remove(): void {
switch (this.field.parent.type) {
case 'object':
- if (this.editorComponentInstance) {
- this.editorComponentInstance.hide(this.field);
- }
+ this.field.props.setHide ? this.field.props.setHide(this.field, true): this.field.hide = true;
break;
case 'array':
this.field.parent.props.remove(Number(this.field.key));
@@ -85,12 +74,18 @@ export class FormFieldWrapperComponent extends FieldWrapper implements OnInit {
canRemove(): boolean {
switch (this.field.parent.type) {
case 'object':
- return this.editorComponentInstance ? this.editorComponentInstance.canHide(this.field) : false;
- case 'array':
- return this.field.parent.props.canRemove();
- default:
- return false;
- }
+ if (!this.field.props.editorConfig.longMode) {
+ return false;
+ }
+ return (
+ !this.field.props.required &&
+ !this.field.hide
+ );
+ case 'array':
+ return this.field.parent.props.canRemove();
+ default:
+ return false;
+ }
}
/**
diff --git a/projects/rero/ng-core/src/public-api.ts b/projects/rero/ng-core/src/public-api.ts
index 6def9f5a..a27d1224 100644
--- a/projects/rero/ng-core/src/public-api.ts
+++ b/projects/rero/ng-core/src/public-api.ts
@@ -63,6 +63,7 @@ export * from './lib/record/editor/type/switch/switch.component';
export * from './lib/record/editor/utils';
export * from './lib/record/editor/widgets/add-field-editor/add-field-editor.component';
export * from './lib/record/editor/widgets/dropdown-label-editor/dropdown-label-editor.component';
+export * from './lib/record/editor/services/jsonschema.service';
export * from './lib/record/editor/wrappers/toggle-wrapper/toggle-wrappers.component';
export * from './lib/record/export-button/export-button.component';
export * from './lib/record/record';