Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getUiOptions,
isFilesArray,
deepEquals,
getSchemaType,
} from "../../utils";
import UnsupportedField from "./UnsupportedField";

Expand All @@ -29,7 +30,8 @@ function getFieldComponent(schema, uiSchema, idSchema, fields) {
if (typeof field === "string" && field in fields) {
return fields[field];
}
const componentName = COMPONENT_TYPES[schema.type];

const componentName = COMPONENT_TYPES[getSchemaType(schema)];
return componentName in fields
? fields[componentName]
: () => {
Expand Down
10 changes: 9 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ export function getDefaultRegistry() {
};
}

export function getSchemaType(schema) {
let { type } = schema;
if (!type && schema.enum) {
type = "string";
}
return type;
}

export function getWidget(schema, widget, registeredWidgets = {}) {
const { type } = schema;
const type = getSchemaType(schema);

function mergeOptions(Widget) {
// cache return value as property of widget for proper react reconciliation
Expand Down
10 changes: 10 additions & 0 deletions test/StringField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ describe("StringField", () => {
expect(node.querySelectorAll(".field select")).to.have.length.of(1);
});

it("should render a string field for an enum without a type", () => {
const { node } = createFormComponent({
schema: {
enum: ["foo", "bar"],
},
});

expect(node.querySelectorAll(".field select")).to.have.length.of(1);
});

it("should render a string field with a label", () => {
const { node } = createFormComponent({
schema: {
Expand Down