Skip to content

Commit

Permalink
formly: improve id generator
Browse files Browse the repository at this point in the history
* Added numerical position on key generation for OneOf.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
Co-Authored-by: Johnny Mariéthoz <johnny.mariethoz@rero.ch>
  • Loading branch information
Garfield-fr and jma committed Aug 18, 2020
1 parent 27e27d7 commit 405eb3e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions projects/rero/ng-core/src/lib/record/editor/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,21 @@ export const fieldIdGenerator: FormlyExtension = {
*/
export function getKey(field: any): string {
let parentKey = null;
const keyParams = [];

if (field.parent != null) {
parentKey = getKey(field.parent);
keyParams.push(parentKey);
}

if (parentKey != null) {
let newId = parentKey;
if (field.key != null) {
newId = [parentKey, field.key].join('-');
keyParams.push(field.key);
} else {
keyParams.push(field.id.replace(/.*__(\d+)$/, '$1'));
}
return newId;

return keyParams.join('-');
}
return field.key;
}
Expand Down

0 comments on commit 405eb3e

Please sign in to comment.