Skip to content

Commit

Permalink
Fixes #9: Default object field property labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Dec 29, 2015
1 parent fc6164d commit fec5bc4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/fields/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class ArrayField extends Component {
}

render() {
const {schema, uiSchema} = this.props;
const {schema, uiSchema, name} = this.props;
const {items} = this.state;
return (
<fieldset
className={`field field-array field-array-of-${schema.items.type}`}>
<legend>{schema.title}</legend>
<legend>{schema.title || name}</legend>
{schema.description ? <div>{schema.description}</div> : null}
<div className="array-item-list">{
items.map((item, index) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/fields/BooleanField.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import React, { PropTypes } from "react";
import { defaultFieldValue, getAlternativeWidget } from "../../utils";
import CheckboxField from "./../widgets/CheckboxWidget";

function BooleanField({schema, uiSchema, formData, required, onChange}) {
function BooleanField({schema, name, uiSchema, formData, required, onChange}) {
const {title, description} = schema;
const {widget} = uiSchema;
const commonProps = {
type: schema.type,
onChange,
label: title,
label: title || name,
placeholder: description,
defaultValue: schema.default,
value: defaultFieldValue(formData, schema),
Expand Down
4 changes: 2 additions & 2 deletions src/components/fields/StringField.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import TextWidget from "./../widgets/TextWidget";
import SelectWidget from "./../widgets/SelectWidget";


function StringField({schema, uiSchema, formData, required, onChange}) {
function StringField({schema, name, uiSchema, formData, required, onChange}) {
const {type, title, description} = schema;
const {widget} = uiSchema;
const commonProps = {
type: type,
label: title,
label: title || name,
placeholder: description,
onChange,
value: defaultFieldValue(formData, schema),
Expand Down
21 changes: 15 additions & 6 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ describe("Form", () => {
},
properties: {
foo: {
title: "foo",
title: "Foo",
type: "string",
},
bar: {
Expand All @@ -442,20 +442,27 @@ describe("Form", () => {
}
};

it("should render an fieldset", () => {
it("should render a fieldset", () => {
const {node} = createComponent({schema});

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

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

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

it("should render a default property label", () => {
const {node} = createComponent({schema});

expect(node.querySelector(".field-boolean label > span").textContent)
.eql("bar");
});

it("should render a string property", () => {
const {node} = createComponent({schema});

Expand Down Expand Up @@ -486,7 +493,7 @@ describe("Form", () => {
expect(node.querySelector("input[type=text]").getAttribute("required"))
.eql("");
expect(node.querySelector(".field label").textContent)
.eql("foo*");
.eql("Foo*");
});

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

it("should render boolean option labels", () => {
const {node} = createComponent({schema, uiSchema});
const labels = [].map.call(node.querySelectorAll("label span"),
node => node.textContent);
const labels = [].map.call(
node.querySelectorAll(".field-radio-group label > span"),
node => node.textContent);

expect(labels)
.eql(["true", "false"]);
});
Expand Down

0 comments on commit fec5bc4

Please sign in to comment.