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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ The following props are passed to a custom field template component:
- `hidden`: A boolean value stating if the field should be hidden.
- `required`: A boolean value stating if the field is required.
- `readonly`: A boolean value stating if the field is read-only.
- `disabled`: A boolean value stating if the field is disabled.
- `displayLabel`: A boolean value stating if the label should be rendered or not. This is useful for nested fields in arrays where you don't want to clutter the UI.
- `fields`: An array containing all Form's fields including your [custom fields](#custom-field-components) and the built-in fields.
- `schema`: The schema object for this field.
Expand Down
1 change: 1 addition & 0 deletions src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ function SchemaFieldRender(props) {
label,
hidden,
required,
disabled,
readonly,
displayLabel,
classNames,
Expand Down
40 changes: 40 additions & 0 deletions test/FieldTemplate_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";

import { expect } from "chai";
import { createFormComponent, createSandbox } from "./test_utils";

describe("FieldTemplate", () => {
let sandbox;

beforeEach(() => {
sandbox = createSandbox();
});

afterEach(() => {
sandbox.restore();
});

describe("Custom FieldTemplate for disabled property", () => {
function FieldTemplate(props) {
return <div className={props.disabled ? "disabled" : "foo"} />;
}

it("should render with disabled when ui:disabled is truthy", () => {
const { node } = createFormComponent({
schema: { type: "string" },
uiSchema: { "ui:disabled": true },
FieldTemplate,
});
expect(node.querySelectorAll(".disabled")).to.have.length.of(1);
});

it("should render with disabled when ui:disabled is falsey", () => {
const { node } = createFormComponent({
schema: { type: "string" },
uiSchema: { "ui:disabled": false },
FieldTemplate,
});
expect(node.querySelectorAll(".disabled")).to.have.length.of(0);
});
});
});