Linked fields in JsonForms

Hi Team,

We have schema, which contains 2 fields but the data in both fields should be in sync, so do we have any provision like linked fields
So we have schema like below, and name field is coming twice one at root second inside config, but what we want in data is both fields should be present and data should be in sync, update made in one field should reflect in second field as well

{
    "properties": {
      "name": {
            "type": "string",
            "description": "Name field",
            "x-path": "../config/name"
        },
        "config": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "Name field"
                },
                "title": {
                    "type": "string",
                    "description": "title field"
                }
            }
        }
    }
}

Hi @rohan.thakare,

First I would think about whether this is really necessary. Seems weird to duplicate data. If it’s just about visuals, then you can accomplish this via the UI Schema. When pointing two or more controls to the same data they will automatically be synced. Or just use the “inner” property at form-time and then duplicate it after the fact when you need to talk to some other API.

Of course I don’t know about your requirements, so in case you need to handle it like this then you have two different approaches available:

  • Sync the data within JSON Forms. In that case you could register custom renderers (in this case for name and config/name) which would then not only modify their data but also the other path. The information in the schema shown is sufficient to implement this generically with some analysis (e.g. check for all properties whether some other x-path points to it). For implementation you could probably reuse all existing primitive renderers by wrapping them and just handing over a specialized handleChange method.
  • Sync the data outside of JSON Forms. In that case you would listen to the data change events coming from JSON Forms and then modify the data before feeding it back to JSON Forms. This makes especially sense when you already have this logic in place somewhere else in your app. The downside is that you will rerender the form twice for all these cases, however that should usually not be noticable