Skip to content

Commit fec5bc4

Browse files
committed
Fixes #9: Default object field property labels.
1 parent fc6164d commit fec5bc4

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

src/components/fields/ArrayField.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ class ArrayField extends Component {
6262
}
6363

6464
render() {
65-
const {schema, uiSchema} = this.props;
65+
const {schema, uiSchema, name} = this.props;
6666
const {items} = this.state;
6767
return (
6868
<fieldset
6969
className={`field field-array field-array-of-${schema.items.type}`}>
70-
<legend>{schema.title}</legend>
70+
<legend>{schema.title || name}</legend>
7171
{schema.description ? <div>{schema.description}</div> : null}
7272
<div className="array-item-list">{
7373
items.map((item, index) => {

src/components/fields/BooleanField.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import React, { PropTypes } from "react";
33
import { defaultFieldValue, getAlternativeWidget } from "../../utils";
44
import CheckboxField from "./../widgets/CheckboxWidget";
55

6-
function BooleanField({schema, uiSchema, formData, required, onChange}) {
6+
function BooleanField({schema, name, uiSchema, formData, required, onChange}) {
77
const {title, description} = schema;
88
const {widget} = uiSchema;
99
const commonProps = {
1010
type: schema.type,
1111
onChange,
12-
label: title,
12+
label: title || name,
1313
placeholder: description,
1414
defaultValue: schema.default,
1515
value: defaultFieldValue(formData, schema),

src/components/fields/StringField.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import TextWidget from "./../widgets/TextWidget";
55
import SelectWidget from "./../widgets/SelectWidget";
66

77

8-
function StringField({schema, uiSchema, formData, required, onChange}) {
8+
function StringField({schema, name, uiSchema, formData, required, onChange}) {
99
const {type, title, description} = schema;
1010
const {widget} = uiSchema;
1111
const commonProps = {
1212
type: type,
13-
label: title,
13+
label: title || name,
1414
placeholder: description,
1515
onChange,
1616
value: defaultFieldValue(formData, schema),

test/index_test.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ describe("Form", () => {
433433
},
434434
properties: {
435435
foo: {
436-
title: "foo",
436+
title: "Foo",
437437
type: "string",
438438
},
439439
bar: {
@@ -442,20 +442,27 @@ describe("Form", () => {
442442
}
443443
};
444444

445-
it("should render an fieldset", () => {
445+
it("should render a fieldset", () => {
446446
const {node} = createComponent({schema});
447447

448448
expect(node.querySelectorAll("fieldset"))
449449
.to.have.length.of(1);
450450
});
451451

452-
it("should render an fieldset legend", () => {
452+
it("should render a fieldset legend", () => {
453453
const {node} = createComponent({schema});
454454

455455
expect(node.querySelector("fieldset > legend").textContent)
456456
.eql("my object");
457457
});
458458

459+
it("should render a default property label", () => {
460+
const {node} = createComponent({schema});
461+
462+
expect(node.querySelector(".field-boolean label > span").textContent)
463+
.eql("bar");
464+
});
465+
459466
it("should render a string property", () => {
460467
const {node} = createComponent({schema});
461468

@@ -486,7 +493,7 @@ describe("Form", () => {
486493
expect(node.querySelector("input[type=text]").getAttribute("required"))
487494
.eql("");
488495
expect(node.querySelector(".field label").textContent)
489-
.eql("foo*");
496+
.eql("Foo*");
490497
});
491498

492499
it("should fill fields with form data", () => {
@@ -638,8 +645,10 @@ describe("Form", () => {
638645

639646
it("should render boolean option labels", () => {
640647
const {node} = createComponent({schema, uiSchema});
641-
const labels = [].map.call(node.querySelectorAll("label span"),
642-
node => node.textContent);
648+
const labels = [].map.call(
649+
node.querySelectorAll(".field-radio-group label > span"),
650+
node => node.textContent);
651+
643652
expect(labels)
644653
.eql(["true", "false"]);
645654
});

0 commit comments

Comments
 (0)