Skip to content

Commit

Permalink
fix(editor): incorrect model assignment
Browse files Browse the repository at this point in the history
In the case of the array type, the model is not filled
in correctly when a new entry is inserted.

* Closes rero/rero-ils#3661.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
Co-Authored-by: Johnny Mariethoz <[email protected]>
  • Loading branch information
Garfield-fr and jma committed May 7, 2024
1 parent afcf2d7 commit c9a89e4
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
import { Component, OnInit } from '@angular/core';
import { FieldArrayType, FormlyFieldConfig } from '@ngx-formly/core';
import { cloneDeep } from 'lodash-es';

/**
* Component for displaying array fields in editor.
Expand Down Expand Up @@ -73,7 +74,13 @@ export class ArrayTypeComponent extends FieldArrayType implements OnInit {
* @param i - number, the position to add the element
*/
add(i: number, initialModel?: any) {
// There is a bug in ngx-formly which does not correctly
// assign the model to the multiSchema.
// Solution: Copy the model and re-assign after adding.
const model = cloneDeep(this.model);
model.splice(i, 0, initialModel ? cloneDeep(initialModel) : undefined);
super.add(i, initialModel);
this.formControl.patchValue(model, { onlySelf: true, emitEvent: false});
this.setFocusInChildren(this.field.fieldGroup[i]);
}

Expand Down

0 comments on commit c9a89e4

Please sign in to comment.