koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
538 stars 154 forks source link

Populate Select using selected values of another Select #375

Closed rmirro closed 1 year ago

rmirro commented 1 year ago

I have a select that I'd like to populate with selected (checkbox) items from another select.

I seem to have this partially working, although the dynamically populated select is displaying the item value as the title, but I'd like the title of the select item displayed.

Here is a codepen to demonstrate how it's working now.

Is this type of functionality supported?


I've tried defining the dynamic select as both a regular property and as a dependency below.

Screen Shot 2022-09-07 at 12 21 14 PM


Schema:

const schema = {
  type: 'object',
  description: 'Select As Dependency',
  'x-display': 'expansion-panels',
  'x-props': {
    mandatory: false,
  },
  'x-options': {
    hideReadOnly: true,
  },
  properties: {
    cards: {
      title: 'Cards',
      description: 'Select cards that should be enabled.',
      type: 'object',

      properties: {
        availableCards: {
          type: 'array',
          title: 'Available Cards',
          'x-display': 'checkbox',
          items: {
            type: 'string',
            oneOf: [
              {
                const: 'card-one',
                title: 'Card One',
              },
              {
                const: 'card-two',
                title: 'Card Two',
              },
              {
                const: 'card-three',
                title: 'Card Three',
              },
              {
                const: 'card-four',
                title: 'Card Four',
              },
            ],
          },
        },
        enabledCards: {
          type: 'array',
          title: 'Enabled Cards',
          items: {
            type: 'string',
          },
          'x-display': 'checkbox',
          'x-fromData': 'parent.value.availableCards',
          'x-itemTitle': 'title',
          'x-itemKey': 'const',
        },
      },
      dependencies: {
        availableCards: {
          properties: {
            enabledCardsDependency: {
              type: 'array',
              title: 'Enabled Cards Dependency',
              items: {
                type: 'string',
              },
              'x-display': 'checkbox',
              'x-fromData': 'parent.value.availableCards',
              'x-itemTitle': 'title',
              'x-itemKey': 'const',
            },
          },
        },
      },
    },
  },
};
albanm commented 1 year ago

I just released version 2.19.0. I added the schema to the context given to expressions, so this use case is now supported if you activate a more powerful expression mode (evalExpr of newFunction), see this example for more details.

rmirro commented 1 year ago

Wow, that looks perfect!

I really lucked out with the timing of this new release! 😄

rmirro commented 1 year ago

It seems like 2.19.0 provides exactly what I was hoping for.