guillotinaweb / ngx-schema-form

HTML form generation based on JSON Schema
MIT License
485 stars 174 forks source link

Remove invisible elements from model at root level #453

Closed KBroichhausen closed 1 year ago

KBroichhausen commented 1 year ago

Due to Object.assign elements on root level like this.model =

{
   "old": "foo"
}

and value =

{
   "new": "bar"
}

gets merged to

{
   "old": "foo",
   "new": "bar"
}

but old is not visible anymore and should be removed from the model.

Assignment like this.model = value is also bad because this leads to bad behaviour with two-way data binding. I tried to use assignment with a change event to tell the parent that the child (FormComponent) has changed the model but because FormComponent implements OnChanges I had a loop.

Not the best fix but at least it just iterates through the keys at root level of the model and not into the nested structure.