Skip to content

Custom renderer can not be applied (aka tested) for properties in sub-forms #2188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KIC opened this issue Oct 6, 2023 · 2 comments
Closed

Comments

@KIC
Copy link

KIC commented Oct 6, 2023

Describe the bug

As a follow up on #2187 it seems not to be possible to test for custom renderers ( https://jsonforms.io/docs/tutorial/custom-renderers ) based on the scope property name in the case of multiforms (nested form). While I have a special search able object with a very distinctive name which I want to test for, the actual property name never gets passed to the tester. Instead the partent form property name gets passed along:

type: "object",
definitions: {
  Client: {
      "name": {"type": "string"}
      "parent": {
      "type": "array",
          "items": {
              "$ref": "#/definitions/SearchableObject"
          }
      }
  },
  SearchableObject: {
      "type": "object",
      "properties": {
          "a_very_special_field": {
              "type": "integer"
          }
      },
      "required": []
  },
 properties: {
    "Client": {
        "$ref": "#/definitions/Client"
    }
}

tester:

export const nameStartsWith = 
    (prefix) => (uischema) => { 
        if (_.isEmpty(prefix) || !isControl(uischema)) {
            return false;
        }
        
        const parts = uischema.scope.split("/")
        console.log("nameStartsWith", parts, uischema)  
        return parts[parts.length - 1].startsWith(prefix)
    } 

the uischema.scope will actually never be a_very_special_field but only parent. This means we can not have custom renderers based on fields in sub forms.

Expected behavior

For the follwoing tester

export const nameStartsWith = 
    (prefix) => (uischema) => { 
        if (_.isEmpty(prefix) || !isControl(uischema)) {
            return false;
        }
        
        const parts = uischema.scope.split("/")
        console.log("nameStartsWith", parts, uischema)
        return parts[parts.length - 1].startsWith(prefix)
    } 

the uischema.scope should actually be: #/definitions/SearchableObject/a_very_special_field and not parent

Steps to reproduce the issue

Write a tester based on a property of an embedded property i.e. an array property.

Screenshots

No response

In which browser are you experiencing the issue?

Google Chrome

Which Version of JSON Forms are you using?

3.1.0

Framework

React

RendererSet

Other (please specify in the Additional context field)

Additional context

custom renderer

@sdirix
Copy link
Member

sdirix commented Oct 18, 2023

I converted the example to this as it was invalid/incomplete:

{
  "type": "object",
  "definitions": {
    "Client": {
      "type": "object",
      "properties": {
        "name": {"type": "string"},
        "parent": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/SearchableObject"
          }
        }
      }
    },
    "SearchableObject": {
      "type": "object",
      "properties": {
        "a_very_special_field": {
          "type": "integer"
        }
      },
      "required": []
    }
  },
  "properties": {
    "Client": {
      "$ref": "#/definitions/Client"
    }
  }
}

In general each rendered control will be tested for. This means the a_very_special_field will also be tested for in case it's rendered.

However with arrays and objects we use intermediate levels of (sub)schemas. In your case the last sub-schema is the parent array. Its subschema for the items is

    {
      "type": "object",
      "properties": {
        "a_very_special_field": {
          "type": "integer"
        }
      },
      "required": []
    }

Therefore the tested for scope will be #/properties/a_very_special_field.


Also note that we have a special renderer set for table cells. In this example schema by default a table renderer will be used because the object is shallow and fits into a table. Therefore not the testers of the renderers will be used but instead the testers of the cells.

@sdirix
Copy link
Member

sdirix commented Oct 24, 2023

I'll close this for now. If you have further questions, please check our forums.

@sdirix sdirix closed this as completed Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants