Setting a Field as Required Depending on a JSON Value

I created a page builder with different sections and various variants.

In my variant collection, I added a JSON field structured like this:

json

CopierModifier

[
    {
        "name": "field1",
        "required": true
    },
    {
        "name": "field2",
        "required": false
    }
]

In my section, can I conditionally set a field as required based on its required value in the JSON while targeting the field by its name value?

For example, in the section, if this variant is selected, field1 should be required.

The main issue is that I cannot access the variant object. It could be useful in many cases not only in conditions.

Should I have to edit the raw filter as I would have done with the SDK ?

Thank you in advance :rabbit:

1 Answer

1

Directus is not currently capable of filtering JSON data types.

Open Feature Request:

Thank you, Tim. I had already seen this GitHub issue before posting, but I wasn't sure it was related to my problem. What a pity! :( I guess an extension or a hook could be a solution — or maybe even a flow (though I'm not sure about the latter, as it would need to detect the change before creation, only when a field is selected).

Is there a standard work around for not being able to filter JSON fields. We us a lot of JSON fields in our database and the limitation is, well, limiting. :grimacing:. Its particularly frustrating because there is not visible cue that the limit exists... you can set a filter based on a JSON field, just nothing happens.