Skip to content
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

Control path resolution fails for "dynamically" added properties via conditional schema compositions #1907

Closed
nmaier95 opened this issue Mar 30, 2022 · 0 comments · Fixed by #1909
Labels
Milestone

Comments

@nmaier95
Copy link
Contributor

Describe the bug

Imagine having the following two schemas (i used the vue3 seeder repository as a basis):

const schema = {
    type: 'object',
    properties: {
        name: {
            type: 'string',
            minLength: 1,
            description: 'The task\'s name',
        },
        recurrence: {
            type: 'string',
            enum: ['Never', 'Daily', 'Weekly', 'Monthly'],
        },
    },
    anyOf: [
        {
            if: {
                properties: {
                    recurrence: {
                        const: 'Never'
                    }
                }
            },
            then: {
                properties: {
                    lastname: {
                        type: 'string'
                    }
                }
            }
        },
    ]
};

const uischema = {
    type: 'HorizontalLayout',
    elements: [
        {
            type: 'VerticalLayout',
            elements: [
                {
                    type: 'Control',
                    scope: '#/properties/name',
                },
                {
                    type: 'Control',
                    scope: '#/properties/recurrence',
                },
                {
                    type: 'Control',
                    scope: '#/anyOf/0/then/properties/lastname',
                    rule: {
                        effect: 'SHOW',
                        condition: {
                            scope: '#/properties/recurrence',
                            schema: {
                                const: 'Never'
                            }
                        }
                    }
                },
            ],
        },
    ],
};

Just for reference: I used the following json-schema documentation to build such a construct json-schema.org/.... See the second example block underneath If-Then-Else. My intention is to add an arbitrary set of properties (here just: lastname) to a schema if some condition is met (here: if recurrence equals 'Never').

The actual issue is the following: Every Control-Renderer receives a property called control which contains the necessary information for my current form element. This control also holds a property path which is derived from the scope-property of the ui-schema and is further used as the key for the data object to be created via the form.
E.g.: scope: '#/properties/name' -> control.path: 'name' -> { name: 'Jon', ... }.
For the property which is only added if a certain condition is met, my scope-property is the following: #/anyOf/0/then/properties/lastname. If I now inpsect via vue-devtools what my control.path holds for my actually rendered control of #/anyOf/0/then/properties/lastname it equals: control.path: 'properties'.

Expected behavior

control.path holds the correctly transformed value: lastname.

Steps to reproduce the issue

  1. Checkout and run the vue3 seed repo
  2. Replace the two sample schemas with the ones from above
  3. Inspect the lastname field via vue-devtools
  4. See the wrong value of control.path

Screenshots

No response

In which browser are you experiencing the issue?

Google Chrome

Framework

Core, Vue 3

RendererSet

Vanilla

Additional context

No response

@sdirix sdirix added this to the 3.0 milestone May 12, 2022
@sdirix sdirix added the core label May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants