Rules not getting applied when data changed dynamically during runtime

When the data(bind in html) as well as jsonform service core getting updated manually, rules are not getting executed(enabling/disabling fields). It was working fine in previous version. After using the 2.5.2 version, the rules are not getting updated as per the data.

Hi @Sanka16, can you give a concrete code example?

Note that 2.5.2 is already over 6 months old. We’ll soon release JSON Forms 3.0. You can try it today via the next stream, i.e. @jsonforms/core@next etc.

Am trying to updatecore when we click a button which is outside jsonform tag.

<button (click)= {this will change the data bind in jsonform tag as well as updatecore action triggered}>

When the click action happens, the data is getting changed and jsonform core is getting updated but the form fields are not getting refreshed and I am expecting few fields to be enabled when I click the button which is not happening now. It was happening in older version.

Is this related to the Angular renderers? Did you see the migration guide for Angular users updating to 2.5.X?

yes Stefan. We upgraded our jsonforms in our angular app and tried the similar way as per migration guide. But, rule effect not working on fields when the form data is changed manually. Any pointers on how to bind the data change outside jsonforms tag ?
We are using the similar code like below.
<jsonforms
[data]=“data”
[schema]=“schema”
[uischema]=“uischema”
[renderers]=“renderers”
(dataChange)=“onDataChange($event)”
>

Tried init action, updatecore, updatecorestate actions but no luck. Though the data and core data getting updated, enabling/disabling effect not happening as per rules. We are stuck here and trying to solve it but till now no luck. We are coming to you after a lot of tries.

Hi @Sanka16,

is there any way you can share an executable example somewhere? For example by replicating the bug in our Angular seed?

It’s very hard to diagnose the problem without detailed information.

HTML change -----

<jsonforms
[data]=“data”
[schema]=“schema”
[uischema]=“uischema”
[renderers]=“renderers”
(dataChange)=“onDataChange($event)”

-----Add this button------
<button (click)=“changeData()”>click

In Jsonformcomponent ts file , add this below function--------------------
changeData(){
this.data.orders[0].assignee = ‘foo’;
}

If we add a condition in UIschema such that, if assignee is foo, then disable a field, it is not working

So, when changing the data manually, rules are not working

It doesn’t work because the change detection of JSON Forms is bypassed. JSON Forms will properly update when the data changed via two mechanisms:

  • A new data instance is handed over to the JSON Forms component
  • An update event is triggered

Therefore you either need to dispatch an update action for the respective data path or you need to hand over a new data object instance to JSON Forms. Nested data changes alone are not detected by JSON Forms.

So for example the following should work as fp/set creates new instances for all involved objects

import set from 'lodash/fp/set';

this.data = set('orders.0.assignee', 'foo', this.data);

Thank you. We got the issue now.

This helped out to fix our issue. Now our data is getting changed properly and rules are applied as per our conditions.

1 Like

Its happend with me when i change the rule of my site The Vlogging Tech