josdejong/jsoneditor

enum dropdown in anyOf \ oneOf

Open

#1653 aperta il 21 mar 2025

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)JavaScript (2034 fork)batch import
featurehelp wanted

Metriche repository

Star
 (10.781 star)
Metriche merge PR
 (Merge medio 15h 36m) (3 PR mergiate in 30 g)

Descrizione

Hi! Thanks for the fantastic library!

I have an issue with enums, maybe someone can help me with it.

Given I have a schema:

  rules: {
    type: 'array',
    items: {
      oneOf: [
        {
          type: 'object',
          properties: {
            val: { type: 'number' },
            op: {
              type: 'string',
              enum: ['lessThan', 'greaterThan', 'equals'],
            },
          },
        },
        {
          type: 'object',
          properties: {
            val: { type: ['number', 'string'] },
            op: {
              type: 'string',
              enum: ['before', 'after', 'equals'],
            },
          },
        },
        {
          type: 'object',
          properties: {
            val: { type: 'string' },
            op: {
              type: 'string',
              enum: ['beginsWith', 'endsWith', 'contains', 'equals',]
            },
          },
        },
      ],
    },
  }

If I create a rule with any of those types, validation works well and it displays no errors. However in the op field dropdown always only values from ['lessThan', 'greaterThan', 'equals'] displayed.

I've tried if\then schemas, this actually disables enum dropdowns in general and replaces it with a regular string input mode. I've tried const discriminators, but no luck so far.

Maybe I'm missing something? I would appreciate any help. Thanks.

Guida contributor