mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
Fixed issue with concat component
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { DynamicFormControlLayout, DynamicFormGroupModel, DynamicFormGroupModelConfig, serializable } from '@ng-dynamic-forms/core';
|
||||
import { isNotEmpty } from '../../../../empty.util';
|
||||
import { DsDynamicInputModel } from './ds-dynamic-input.model';
|
||||
import { AuthorityValueModel } from '../../../../../core/integration/models/authority-value.model';
|
||||
import { FormFieldMetadataValueObject } from '../../models/form-field-metadata-value.model';
|
||||
|
||||
export const CONCAT_GROUP_SUFFIX = '_CONCAT_GROUP';
|
||||
@@ -28,8 +27,11 @@ export class DynamicConcatModel extends DynamicFormGroupModel {
|
||||
get value() {
|
||||
const firstValue = (this.get(0) as DsDynamicInputModel).value;
|
||||
const secondValue = (this.get(1) as DsDynamicInputModel).value;
|
||||
|
||||
if (isNotEmpty(firstValue) && isNotEmpty(secondValue)) {
|
||||
return new FormFieldMetadataValueObject(firstValue + this.separator + secondValue);
|
||||
} else if (isNotEmpty(firstValue)) {
|
||||
return new FormFieldMetadataValueObject(firstValue);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -37,14 +39,24 @@ export class DynamicConcatModel extends DynamicFormGroupModel {
|
||||
|
||||
set value(value: string | FormFieldMetadataValueObject) {
|
||||
let values;
|
||||
let tempValue: string;
|
||||
|
||||
if (typeof value === 'string') {
|
||||
values = value ? value.split(this.separator) : [null, null];
|
||||
tempValue = value;
|
||||
} else {
|
||||
values = value ? value.value.split(this.separator) : [null, null];
|
||||
tempValue = value.value;
|
||||
}
|
||||
|
||||
if (values.length > 1) {
|
||||
if (tempValue.includes(this.separator)) {
|
||||
values = tempValue.split(this.separator);
|
||||
} else {
|
||||
values = [tempValue, null];
|
||||
}
|
||||
|
||||
if (values[0]) {
|
||||
(this.get(0) as DsDynamicInputModel).valueUpdates.next(values[0]);
|
||||
}
|
||||
if (values[1]) {
|
||||
(this.get(1) as DsDynamicInputModel).valueUpdates.next(values[1]);
|
||||
}
|
||||
}
|
||||
|
@@ -277,13 +277,17 @@ export class FormBuilderService extends DynamicFormService {
|
||||
}
|
||||
|
||||
getId(model: DynamicPathable): string {
|
||||
let tempModel: DynamicFormControlModel;
|
||||
|
||||
if (this.isArrayGroup(model as DynamicFormControlModel)) {
|
||||
return model.index.toString();
|
||||
} else if (this.isModelInCustomGroup(model as DynamicFormControlModel)) {
|
||||
tempModel = (model as any).parent;
|
||||
} else {
|
||||
return ((model as DynamicFormControlModel).id !== (model as DynamicFormControlModel).name) ?
|
||||
(model as DynamicFormControlModel).name :
|
||||
(model as DynamicFormControlModel).id;
|
||||
tempModel = (model as any);
|
||||
}
|
||||
|
||||
return (tempModel.id !== tempModel.name) ? tempModel.name : tempModel.id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,16 +31,7 @@ export class ConcatFieldParser extends FieldParser {
|
||||
|
||||
let clsGroup: DynamicFormControlLayout;
|
||||
let clsInput: DynamicFormControlLayout;
|
||||
let newId: string;
|
||||
|
||||
if (this.configData.selectableMetadata[0].metadata.includes('.')) {
|
||||
newId = this.configData.selectableMetadata[0].metadata
|
||||
.split('.')
|
||||
.slice(0, this.configData.selectableMetadata[0].metadata.split('.').length - 1)
|
||||
.join('.');
|
||||
} else {
|
||||
newId = this.configData.selectableMetadata[0].metadata
|
||||
}
|
||||
const id: string = this.configData.selectableMetadata[0].metadata;
|
||||
|
||||
clsInput = {
|
||||
grid: {
|
||||
@@ -48,14 +39,14 @@ export class ConcatFieldParser extends FieldParser {
|
||||
}
|
||||
};
|
||||
|
||||
const groupId = newId.replace(/\./g, '_') + CONCAT_GROUP_SUFFIX;
|
||||
const groupId = id.replace(/\./g, '_') + CONCAT_GROUP_SUFFIX;
|
||||
const concatGroup: DynamicConcatModelConfig = this.initModel(groupId, false, false);
|
||||
|
||||
concatGroup.group = [];
|
||||
concatGroup.separator = this.separator;
|
||||
|
||||
const input1ModelConfig: DynamicInputModelConfig = this.initModel(newId + CONCAT_FIRST_INPUT_SUFFIX, label, false, false);
|
||||
const input2ModelConfig: DynamicInputModelConfig = this.initModel(newId + CONCAT_SECOND_INPUT_SUFFIX, label, true, false);
|
||||
const input1ModelConfig: DynamicInputModelConfig = this.initModel(id + CONCAT_FIRST_INPUT_SUFFIX, label, false, false);
|
||||
const input2ModelConfig: DynamicInputModelConfig = this.initModel(id + CONCAT_SECOND_INPUT_SUFFIX, label, true, false);
|
||||
|
||||
if (this.configData.mandatory) {
|
||||
input1ModelConfig.required = true;
|
||||
@@ -69,16 +60,6 @@ export class ConcatFieldParser extends FieldParser {
|
||||
input2ModelConfig.placeholder = this.secondPlaceholder;
|
||||
}
|
||||
|
||||
// Init values
|
||||
if (isNotEmpty(fieldValue)) {
|
||||
const values = fieldValue.value.split(this.separator);
|
||||
|
||||
if (values.length > 1) {
|
||||
input1ModelConfig.value = values[0].trim();
|
||||
input2ModelConfig.value = values[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
// Split placeholder if is like 'placeholder1/placeholder2'
|
||||
const placeholder = this.configData.label.split('/');
|
||||
if (placeholder.length === 2) {
|
||||
@@ -99,6 +80,11 @@ export class ConcatFieldParser extends FieldParser {
|
||||
const concatModel = new DynamicConcatModel(concatGroup, clsGroup);
|
||||
concatModel.name = this.getFieldId();
|
||||
|
||||
// Init values
|
||||
if (isNotEmpty(fieldValue)) {
|
||||
concatModel.value = fieldValue;
|
||||
}
|
||||
|
||||
return concatModel;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user