Conditional Default Value

Hi,

Is it possible to have a conditional default value?

I have an element called extract, which is boolean. It has a default value to be true.

But I also have a rule to hide this field based on property of the other element:

 {
                          "type": "Control",
                          "scope": "#/properties/extract",
                          "label": "Extract",
                          "rule": {
                            "effect": "HIDE",
                            "condition": {
                              "scope": "#/properties/fieldType",
                              "schema": { "enum": [ "custom type",
                              "list of a custom type",
                              "list of lists of a custom type"] }
                            }
                          }
                        },

I have tried below:

    {
                          "type": "Control",
                          "scope": "#/properties/extract",
                          "label": "Extract",
                          "rule": {
                            "effect": "HIDE",
                            "condition": {
                              "scope": "#/properties/fieldType",
                              "schema": { "enum":  [
                                       "custom type",
                                       "list of a custom type",
                                       "list of lists of a custom type"
                               ]},
                              "default": false
                            }
                          }
                        }

But it is not working.

Is it possible to remove default value when it hides?

Thank you

Hi @hima,

In JSON Forms we don’t modify the data just by rendering, i.e. all our rules are just evaluated visually.

I don’t know the specifics of your use case. Usually we recommend using custom renderers for the controls from which originate the change, e.g. in your case it seems like you want to delete extract when fieldType is set to custom type. So a good approach would be to register a custom renderer for extract which not only modifies the extract value, but also adapts all other data as necessary.

Alternatively you could listen to the data changes outside of JSON Forms and hand over a modified new data object to JSON Forms in which fieldTypes was excluded.