@@ -21,7 +21,7 @@ import {
2121 distinctUntilChanged ,
2222 filter ,
2323 map ,
24- take ,
24+ take , tap ,
2525} from 'rxjs/operators' ;
2626
2727import { Metadata } from '../../../../../core/shared/metadata.utils' ;
@@ -76,6 +76,8 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
7676 public otherInfoValues : string [ ] = [ ] ;
7777 public otherInfoValuesUnformatted : string [ ] = [ ] ;
7878
79+ multiValueOnGenerator : boolean ;
80+
7981 protected constructor ( protected vocabularyService : VocabularyService ,
8082 protected layoutService : DynamicFormLayoutService ,
8183 protected validationService : DynamicFormValidationService ,
@@ -195,6 +197,7 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
195197 this . vocabulary$ = this . vocabularyService . findVocabularyById ( this . model . vocabularyOptions . name ) . pipe (
196198 getFirstSucceededRemoteDataPayload ( ) ,
197199 distinctUntilChanged ( ) ,
200+ tap ( ( vocabulary : Vocabulary ) => this . multiValueOnGenerator = vocabulary . multiValueOnGenerator ) ,
198201 ) ;
199202 }
200203
@@ -277,12 +280,14 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
277280 for ( const key in otherInformation ) {
278281 if ( otherInformation . hasOwnProperty ( key ) && key . startsWith ( 'data-' ) ) {
279282 const fieldId = key . replace ( 'data-' , '' ) ;
280- const newValue : FormFieldMetadataValueObject = this . getOtherInformationValue ( otherInformation [ key ] , key ) ;
281- if ( isNotEmpty ( newValue ) ) {
282- const updatedModel = this . formBuilderService . updateModelValue ( fieldId , newValue ) ;
283- if ( isNotEmpty ( updatedModel ) ) {
284- updatedModels . push ( updatedModel ) ;
285- }
283+ const newValues : FormFieldMetadataValueObject [ ] = this . getOtherInformationValue ( otherInformation [ key ] , key ) ;
284+ if ( isNotEmpty ( newValues ) ) {
285+ newValues . forEach ( ( newValue ) => {
286+ const updatedModel = this . formBuilderService . updateModelValue ( fieldId , newValue ) ;
287+ if ( isNotEmpty ( updatedModel ) ) {
288+ updatedModels . push ( updatedModel ) ;
289+ }
290+ } ) ;
286291 }
287292 }
288293 }
@@ -297,43 +302,53 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
297302 }
298303 }
299304
300- getOtherInformationValue ( value : string , key : string ) : FormFieldMetadataValueObject {
305+ getOtherInformationValue ( value : string , key : string ) : FormFieldMetadataValueObject [ ] {
301306 if ( isEmpty ( value ) || key === 'alternative-names' ) {
302307 return null ;
303308 }
304309
305- let returnValue ;
306- if ( value . indexOf ( '::' ) === - 1 ) {
307- returnValue = new FormFieldMetadataValueObject ( value ) ;
308- } else if ( value . indexOf ( '|||' ) === - 1 ) {
309- returnValue = new FormFieldMetadataValueObject (
310- value . substring ( 0 , value . lastIndexOf ( '::' ) ) ,
311- null ,
312- null ,
313- value . substring ( value . lastIndexOf ( '::' ) + 2 ) ,
314- ) ;
310+ let returnValue = [ ] ;
311+ if ( value . indexOf ( '|||' ) === - 1 ) {
312+ returnValue . push ( this . generateFormField ( value ) ) ;
315313 } else if ( value . indexOf ( '|||' ) !== - 1 && this . otherInfoValue ) {
316- const unformattedValue = this . otherInfoValuesUnformatted . find ( otherInfoValue => otherInfoValue . includes ( this . otherInfoValue || this . otherName ) ) ;
317- const authorityValue = hasValue ( unformattedValue ) ? unformattedValue . substring ( unformattedValue . lastIndexOf ( '::' ) + 2 ) : null ;
318- const otherInfo = { } ;
319- let alternativeValue ;
320- otherInfo [ key ] = value ;
321- if ( hasValue ( this . otherName ) ) {
322- const otherValues = value . split ( '|||' ) ;
323- alternativeValue = otherValues [ 0 ] . substring ( 0 , otherValues [ 0 ] . lastIndexOf ( '::' ) ) ;
314+ const otherValues : string [ ] = value . split ( '|||' ) ;
315+ if ( this . multiValueOnGenerator ) {
316+ otherValues . forEach ( ( tmpValue ) => returnValue . push ( this . generateFormField ( tmpValue ) ) ) ;
317+ } else {
318+ const unformattedValue = this . otherInfoValuesUnformatted . find ( otherInfoValue => otherInfoValue . includes ( this . otherInfoValue || this . otherName ) ) ;
319+ const authorityValue = hasValue ( unformattedValue ) ? unformattedValue . substring ( unformattedValue . lastIndexOf ( '::' ) + 2 ) : null ;
320+ let otherInfo = { } ;
321+ let alternativeValue : string ;
322+ otherInfo [ key ] = value ;
323+ if ( hasValue ( this . otherName ) ) {
324+ alternativeValue = otherValues [ 0 ] . substring ( 0 , otherValues [ 0 ] . lastIndexOf ( '::' ) ) ;
325+ }
326+ returnValue . push ( new FormFieldMetadataValueObject (
327+ hasValue ( alternativeValue ) ? alternativeValue : this . otherInfoValue ,
328+ null ,
329+ null ,
330+ authorityValue ,
331+ null ,
332+ null ,
333+ null ,
334+ otherInfo
335+ ) ) ;
324336 }
325- returnValue = new FormFieldMetadataValueObject (
326- hasValue ( alternativeValue ) ? alternativeValue : this . otherInfoValue ,
327- null ,
328- null ,
329- authorityValue ,
330- null ,
337+ }
338+ return returnValue ;
339+ }
340+
341+ private generateFormField ( value : string ) : FormFieldMetadataValueObject {
342+ if ( value . indexOf ( '::' ) === - 1 ) {
343+ return new FormFieldMetadataValueObject ( value ) ;
344+ } else {
345+ return new FormFieldMetadataValueObject (
346+ value . substring ( 0 , value . lastIndexOf ( '::' ) ) ,
331347 null ,
332348 null ,
333- otherInfo ,
349+ value . substring ( value . lastIndexOf ( '::' ) + 2 )
334350 ) ;
335351 }
336- return returnValue ;
337352 }
338353
339354 private hasValidAuthority ( formMetadataValue : FormFieldMetadataValueObject ) {
0 commit comments