# oneOf not producing select field or multiple choice checklist in vanilla renderers

**URL:** <https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574>\
**Category:** General\
**Created:** [January 29, 2025, 6:41am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574 "2025-01-29T06:41:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![edkahara](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/edkahara/32/1209_2.png) [@edkahara](https://jsonforms.discourse.group/u/edkahara)\
**Post date:** [January 29, 2025, 6:41am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/1 "2025-01-29T06:41:49Z")

</div>

`oneOf` is not producing the desired select field and multiple choice checklist, only a basic input field where there should be a checklist and nothing for the multiple choice.

```auto
"@jsonforms/core": "^3.5.1"
"@jsonforms/react": "^3.5.1"
"@jsonforms/vanilla-renderers": "^3.5.1"

const schema = {
  type: "object",
  properties: {
    department: {
      type: "string",
      oneOf: [
        {
          const: "hr",
          title: "Human Resources",
        },
        {
          const: "finance",
          title: "Financial Department",
        },
        {
          const: "it",
          title: "Information Technology",
        },
      ],
    },
    savingsOptions: {
      type: "array",
      uniqueItems: true,
      items: {
        oneOf: [
          {
            const: "checking",
            title: "Checking account",
          },
          {
            const: "savings",
            title: "Savings account",
          },
          {
            const: "roth",
            title: "Roth IRA",
          },
        ],
      },
    },
  },
};

const uischema = {
  type: "VerticalLayout",
  elements: [
    {
      type: "Control",
      scope: "#/properties/department",
      label: "Select Department",
      options: {
        placeholder: "Choose a department",
      },
    },
    {
      type: "Control",
      scope: "#/properties/savingsOptions",
      label: "Select savings options",
    },
  ],
};

```

Here’s a [codesandbox](https://codesandbox.io/p/devbox/hidden-fire-7xggs8)

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [January 29, 2025, 7:05am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/2 "2025-01-29T07:05:49Z")

</div>

Hi @edkahara,

As indicated [here](https://jsonforms.io/docs/renderer-sets), we currently do not include a oneOf/Enum renderer for React Vanilla. However we actually include radio group, to enable it, use

```auto
"options": {
  "format": "radio",
}

```

or

```auto
"options": {
  "format": "radio",
  "orientation": "vertical"
}

```

However supporting oneOf-enum should be straightforward in React Vanilla. Basically copy [this cell](https://github.com/eclipsesource/jsonforms/blob/6af8825e004fe6cbdccd4a522041130561ab82b4/packages/vanilla-renderers/src/cells/EnumCell.tsx), and then bind it against oneOf-enums instead of enum. Feel free to contribute this enhancement 😉

---

<div class="post-metadata">

**Author:** ![edkahara](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/edkahara/32/1209_2.png) [@edkahara](https://jsonforms.discourse.group/u/edkahara)\
**Post date:** [January 29, 2025, 8:13am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/3 "2025-01-29T08:13:21Z")

</div>

I tried patching the package locally to see if creating a `OneOfEnumCell` would work but it didn’t. Here’s my code for it.

`cells/OneOfEnumCell.tsx`

```auto
import React, { useMemo } from 'react';
import {
  EnumCellProps,
  isOneOfEnumControl,
  RankedTester,
  rankWith,
} from '@jsonforms/core';
import {
  TranslateProps,
  withJsonFormsOneOfEnumCellProps,
  withTranslateProps,
} from '@jsonforms/react';
import { i18nDefaults, withVanillaEnumCellProps } from '../util';
import type { VanillaRendererProps } from '../index';

export const OneOfEnumCell = (
  props: EnumCellProps & VanillaRendererProps & TranslateProps
) => {
  const {
    data,
    className,
    id,
    enabled,
    schema,
    uischema,
    path,
    handleChange,
    options,
    t,
  } = props;
  const noneOptionLabel = useMemo(
    () => t('enum.none', i18nDefaults['enum.none'], { schema, uischema, path }),
    [t, schema, uischema, path]
  );

  return (
    <select
      className={className}
      id={id}
      disabled={!enabled}
      autoFocus={uischema.options && uischema.options.focus}
      value={data || ''}
      onChange={(ev) =>
        handleChange(
          path,
          ev.target.selectedIndex === 0 ? undefined : ev.target.value
        )
      }
    >
      {[
        <option value={''} key={'jsonforms.enum.none'}>
          {noneOptionLabel}
        </option>,
      ].concat(
        options.map((optionValue) => (
          <option
            value={optionValue.value}
            label={optionValue.label}
            key={optionValue.value}
          />
        ))
      )}
    </select>
  );
};
/**
 * Default tester for enum controls.
 * @type {RankedTester}
 */
export const oneOfEnumCellTester: RankedTester = rankWith(2, isOneOfEnumControl);

export default withJsonFormsOneOfEnumCellProps(
  withTranslateProps(withVanillaEnumCellProps(OneOfEnumCell))
);

```

`cells/index.ts`

```auto
import BooleanCell, { booleanCellTester } from './BooleanCell';
import DateCell, { dateCellTester } from './DateCell';
import DateTimeCell, { dateTimeCellTester } from './DateTimeCell';
import EnumCell, { enumCellTester } from './EnumCell';
import OneOfEnumCell, { oneOfEnumCellTester } from './OneOfEnumCell';
import IntegerCell, { integerCellTester } from './IntegerCell';
import NumberCell, { numberCellTester } from './NumberCell';
import NumberFormatCell, { numberFormatCellTester } from './NumberFormatCell';
import SliderCell, { sliderCellTester } from './SliderCell';
import TextCell, { textCellTester } from './TextCell';
import TextAreaCell, { textAreaCellTester } from './TextAreaCell';
import TimeCell, { timeCellTester } from './TimeCell';
import * as Customizable from './CustomizableCells';

export {
  BooleanCell,
  booleanCellTester,
  DateCell,
  dateCellTester,
  DateTimeCell,
  dateTimeCellTester,
  EnumCell,
  enumCellTester,
  OneOfEnumCell,
  oneOfEnumCellTester,
  IntegerCell,
  integerCellTester,
  NumberCell,
  numberCellTester,
  NumberFormatCell,
  numberFormatCellTester,
  SliderCell,
  sliderCellTester,
  TextCell,
  textCellTester,
  TextAreaCell,
  textAreaCellTester,
  TimeCell,
  timeCellTester,
};
export { Customizable };

```

Is there a change I’m missing? Here’s the patch

```auto
diff --git a/src/cells/OneOfEnumCell.tsx b/src/cells/OneOfEnumCell.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..3c1e8ae67475604f6a8f5c25b2610805da2ff9a5
--- /dev/null
+++ b/src/cells/OneOfEnumCell.tsx
@@ -0,0 +1,98 @@
+import React, { useMemo } from 'react';
+import {
+ EnumCellProps,
+ isOneOfEnumControl,
+ RankedTester,
+ rankWith,
+} from '@jsonforms/core';
+import {
+ TranslateProps,
+ withJsonFormsOneOfEnumCellProps,
+ withTranslateProps,
+} from '@jsonforms/react';
+import { i18nDefaults, withVanillaEnumCellProps } from '../util';
+import type { VanillaRendererProps } from '../index';
+
+export const OneOfEnumCell = (
+ props: EnumCellProps & VanillaRendererProps & TranslateProps
+) => {
+ const {
+ data,
+ className,
+ id,
+ enabled,
+ schema,
+ uischema,
+ path,
+ handleChange,
+ options,
+ t,
+ } = props;
+ const noneOptionLabel = useMemo(
+ () => t('enum.none', i18nDefaults['enum.none'], { schema, uischema, path }),
+ [t, schema, uischema, path]
+ );
+
+ return (
+ <select
+ className={className}
+ id={id}
+ disabled={!enabled}
+ autoFocus={uischema.options && uischema.options.focus}
+ value={data || ''}
+ onChange={(ev) =>
+ handleChange(
+ path,
+ ev.target.selectedIndex === 0 ? undefined : ev.target.value
+ )
+ }
+ >
+ {[
+ <option value={''} key={'jsonforms.enum.none'}>
+ {noneOptionLabel}
+ </option>,
+ ].concat(
+ options.map((optionValue) => (
+ <option
+ value={optionValue.value}
+ label={optionValue.label}
+ key={optionValue.value}
+ />
+ ))
+ )}
+ </select>
+ );
+};
+/**
+ * Default tester for enum controls.
+ * @type {RankedTester}
+ */
+export const oneOfEnumCellTester: RankedTester = rankWith(2, isOneOfEnumControl);
+
+export default withJsonFormsOneOfEnumCellProps(
+ withTranslateProps(withVanillaEnumCellProps(OneOfEnumCell))
+);
diff --git a/src/cells/index.ts b/src/cells/index.ts
index d098afd0c6c4cbba5325772b2a5211635e1b18c3..5abd2e30ead78792aa0876951c7417f1392bf92a 100644
--- a/src/cells/index.ts
+++ b/src/cells/index.ts
@@ -26,6 +26,7 @@ import BooleanCell, { booleanCellTester } from './BooleanCell';
 import DateCell, { dateCellTester } from './DateCell';
 import DateTimeCell, { dateTimeCellTester } from './DateTimeCell';
 import EnumCell, { enumCellTester } from './EnumCell';
+import OneOfEnumCell, { oneOfEnumCellTester } from './OneOfEnumCell';
 import IntegerCell, { integerCellTester } from './IntegerCell';
 import NumberCell, { numberCellTester } from './NumberCell';
 import NumberFormatCell, { numberFormatCellTester } from './NumberFormatCell';
@@ -44,6 +45,8 @@ export {
   dateTimeCellTester,
   EnumCell,
   enumCellTester,
+ OneOfEnumCell,
+ oneOfEnumCellTester,
   IntegerCell,
   integerCellTester,
   NumberCell,

```

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [January 29, 2025, 9:36am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/4 "2025-01-29T09:36:45Z")

</div>

Hi @edkahara,

Code looks good, however it’s not sufficient to export the cell/tester, you also need to add them to the renderer set [here](https://github.com/eclipsesource/jsonforms/blob/6af8825e004fe6cbdccd4a522041130561ab82b4/packages/vanilla-renderers/src/renderers.ts).

---

<div class="post-metadata">

**Author:** ![edkahara](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/edkahara/32/1209_2.png) [@edkahara](https://jsonforms.discourse.group/u/edkahara)\
**Post date:** [January 29, 2025, 11:46am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/5 "2025-01-29T11:46:39Z")

</div>

Unfortunately, adding that in my patch doesn’t work either.

```auto
diff --git a/src/cells/OneOfEnumCell.tsx b/src/cells/OneOfEnumCell.tsx
new file mode 100644
index 0000000000000000000000000000000000000000..3c1e8ae67475604f6a8f5c25b2610805da2ff9a5
--- /dev/null
+++ b/src/cells/OneOfEnumCell.tsx
@@ -0,0 +1,98 @@
+/*
+ The MIT License
+
+ Copyright (c) 2017-2019 EclipseSource Munich
+ https://github.com/eclipsesource/jsonforms
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ THE SOFTWARE.
+*/
+import React, { useMemo } from 'react';
+import {
+ EnumCellProps,
+ isOneOfEnumControl,
+ RankedTester,
+ rankWith,
+} from '@jsonforms/core';
+import {
+ TranslateProps,
+ withJsonFormsOneOfEnumCellProps,
+ withTranslateProps,
+} from '@jsonforms/react';
+import { i18nDefaults, withVanillaEnumCellProps } from '../util';
+import type { VanillaRendererProps } from '../index';
+
+export const OneOfEnumCell = (
+ props: EnumCellProps & VanillaRendererProps & TranslateProps
+) => {
+ const {
+ data,
+ className,
+ id,
+ enabled,
+ schema,
+ uischema,
+ path,
+ handleChange,
+ options,
+ t,
+ } = props;
+ const noneOptionLabel = useMemo(
+ () => t('enum.none', i18nDefaults['enum.none'], { schema, uischema, path }),
+ [t, schema, uischema, path]
+ );
+
+ return (
+ <select
+ className={className}
+ id={id}
+ disabled={!enabled}
+ autoFocus={uischema.options && uischema.options.focus}
+ value={data || ''}
+ onChange={(ev) =>
+ handleChange(
+ path,
+ ev.target.selectedIndex === 0 ? undefined : ev.target.value
+ )
+ }
+ >
+ {[
+ <option value={''} key={'jsonforms.enum.none'}>
+ {noneOptionLabel}
+ </option>,
+ ].concat(
+ options.map((optionValue) => (
+ <option
+ value={optionValue.value}
+ label={optionValue.label}
+ key={optionValue.value}
+ />
+ ))
+ )}
+ </select>
+ );
+};
+/**
+ * Default tester for enum controls.
+ * @type {RankedTester}
+ */
+export const oneOfEnumCellTester: RankedTester = rankWith(3, isOneOfEnumControl);
+
+export default withJsonFormsOneOfEnumCellProps(
+ withTranslateProps(withVanillaEnumCellProps(OneOfEnumCell))
+);
diff --git a/src/cells/index.ts b/src/cells/index.ts
index d098afd0c6c4cbba5325772b2a5211635e1b18c3..2cc59015c5fa6a92539bc464ef7d1f75372a2ef0 100644
--- a/src/cells/index.ts
+++ b/src/cells/index.ts
@@ -29,6 +29,7 @@ import EnumCell, { enumCellTester } from './EnumCell';
 import IntegerCell, { integerCellTester } from './IntegerCell';
 import NumberCell, { numberCellTester } from './NumberCell';
 import NumberFormatCell, { numberFormatCellTester } from './NumberFormatCell';
+import OneOfEnumCell, { oneOfEnumCellTester } from './OneOfEnumCell';
 import SliderCell, { sliderCellTester } from './SliderCell';
 import TextCell, { textCellTester } from './TextCell';
 import TextAreaCell, { textAreaCellTester } from './TextAreaCell';
@@ -50,6 +51,8 @@ export {
   numberCellTester,
   NumberFormatCell,
   numberFormatCellTester,
+ OneOfEnumCell,
+ oneOfEnumCellTester,
   SliderCell,
   sliderCellTester,
   TextCell,
diff --git a/src/renderers.ts b/src/renderers.ts
index a432d5db47145594ef26e7ee1fe7aa9ea39120b9..680c31651e12c6cdff071eb96614f739b20fe254 100644
--- a/src/renderers.ts
+++ b/src/renderers.ts
@@ -38,6 +38,8 @@ import {
   integerCellTester,
   NumberCell,
   numberCellTester,
+ OneOfEnumCell,
+ oneOfEnumCellTester,
   SliderCell,
   sliderCellTester,
   TextAreaCell,
@@ -97,6 +99,7 @@ export const vanillaCells: { tester: RankedTester; cell: any }[] = [
   { tester: enumCellTester, cell: EnumCell },
   { tester: integerCellTester, cell: IntegerCell },
   { tester: numberCellTester, cell: NumberCell },
+ { tester: oneOfEnumCellTester, cell: OneOfEnumCell },
   { tester: sliderCellTester, cell: SliderCell },
   { tester: textAreaCellTester, cell: TextAreaCell },
   { tester: textCellTester, cell: TextCell },

```

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [January 29, 2025, 12:19pm UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/6 "2025-01-29T12:19:57Z")

</div>

Works for me!

 ![image](https://global.discourse-cdn.com/free1/uploads/jsonforms/original/2X/8/8a0f84f3abe99ee50ca849896649c119b41d2223.png)

If you only patch the `@jsonforms/vanilla-renderers` in your `node_modules` directory, then this of course not sufficient. We only provide the source files for debugging support, the actual code is located in `lib/jsonforms-react-vanilla.esm.js` (or `lib/jsonforms-react-vanilla.cjs.js` if you’re consuming the commonjs variant).

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [January 31, 2025, 8:09am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/7 "2025-01-31T08:09:05Z")

</div>

@edkahara Will you open a contribution to add these renderers to JSON Forms?

---

<div class="post-metadata">

**Author:** ![edkahara](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/edkahara/32/1209_2.png) [@edkahara](https://jsonforms.discourse.group/u/edkahara)\
**Post date:** [January 31, 2025, 9:38am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/8 "2025-01-31T09:38:09Z")

</div>

Yes, I’ve been pre-occupied with other tasks. I should be able to open it tomorrow. Is that okay with you?

---

<div class="post-metadata">

**Author:** ![edkahara](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/edkahara/32/1209_2.png) [@edkahara](https://jsonforms.discourse.group/u/edkahara)\
**Post date:** [January 31, 2025, 9:43am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/9 "2025-01-31T09:43:32Z")

</div>

I also want to add the ability to remove the empty option so that if someone doesn’t want it on the field they don’t have to build anything custom.

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [January 31, 2025, 9:51am UTC](https://jsonforms.discourse.group/t/oneof-not-producing-select-field-or-multiple-choice-checklist-in-vanilla-renderers/2574/10 "2025-01-31T09:51:18Z")

</div>

Hi @edkahara,

Great!

> I also want to add the ability to remove the empty option so that if someone doesn’t want it on the field they don’t have to build anything custom.

Fine with me! We should make it configurable via an uischema option.
