Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
251974c
fix HiddenWidget error when value is undefined
olzraiti Jul 12, 2016
8e69465
add context prop
olzraiti Jul 20, 2016
7ae018c
Replace tabs with spaces and add context PropType to Form.
olzraiti Jul 20, 2016
1217215
Pass context to FieldTemplate
olzraiti Aug 19, 2016
4136956
Fix passing context to SchemaField
olzraiti Aug 19, 2016
f8158b9
Replace tabs with spaces
olzraiti Aug 19, 2016
9eeaf75
replace context with formContext
olzraiti Aug 26, 2016
39fb8c3
Don't pass formContext to fields that don't use it
olzraiti Aug 26, 2016
7ada187
Remove duplicate default export from Form
olzraiti Aug 26, 2016
6ab8b12
Add tests for formContext
olzraiti Aug 26, 2016
933f808
Fix formContext tests lint issues
olzraiti Aug 26, 2016
b7670f4
FormContext is passed internally inside registry. Pass formContext to…
olzraiti Aug 29, 2016
770f761
update README
olzraiti Aug 29, 2016
295e572
fix lint and package.json
olzraiti Aug 29, 2016
7bc5952
fix tests. FormContext must be and object.
olzraiti Aug 29, 2016
90c0bd8
Fix minor style issues
olzraiti Aug 30, 2016
2861c92
Update README
olzraiti Aug 30, 2016
9e0caac
Merge branch 'master' of https://github.com/mozilla-services/react-js…
olzraiti Aug 30, 2016
9c158ed
Use empty title instead of name
olzraiti Aug 30, 2016
4974362
Use empty label instead of name
olzraiti Aug 30, 2016
8d120e4
Add tests for passing titles/labels
olzraiti Sep 30, 2016
a919ae1
fix lint issues
olzraiti Sep 30, 2016
2dc4169
Merge branch 'master' of https://github.com/mozilla-services/react-js…
olzraiti Oct 26, 2016
a76d9a6
Merge branch 'master' of https://github.com/mozilla-services/react-js…
olzraiti Nov 2, 2016
cfc3afa
Merge branch 'master' of https://github.com/mozilla-services/react-js…
olzraiti Nov 8, 2016
9f6298e
Merge branch 'master' of https://github.com/mozilla-services/react-js…
olzraiti Jan 2, 2017
2c29a0f
Merge branch 'master' of https://github.com/mozilla-services/react-js…
olzraiti Jan 12, 2017
5d978df
Pass formContext to the files array and multiselect
olzraiti Jan 13, 2017
2402511
Merge branch 'master' of https://github.com/mozilla-services/react-js…
olzraiti Jan 30, 2017
f1c68a5
Merge branch 'master' into fixFormContextFilesAndMultiSelect
olzraiti Jan 30, 2017
672a2f2
Pass formContext to ArrayFieldTemplate
olzraiti Jan 30, 2017
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 @@ -776,6 +776,7 @@ The following props are passed to each `ArrayFieldTemplate`:
- `required`: A boolean value stating if the array is required.
- `schema`: The schema object for this array.
- `title`: A string value containing the title for the array.
- `formContext`: The `formContext` object that you passed to Form.

The following props are part of each element in `items`:

Expand Down
10 changes: 7 additions & 3 deletions src/components/fields/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class ArrayField extends Component {
readonly,
autofocus,
registry,
formContext,
onBlur
} = this.props;
const title = (schema.title === undefined) ? name : schema.title;
Expand Down Expand Up @@ -320,7 +321,8 @@ class ArrayField extends Component {
required,
schema,
title,
TitleField
TitleField,
formContext
};

// Check if a custom render function was passed in
Expand All @@ -331,7 +333,7 @@ class ArrayField extends Component {
renderMultiSelect() {
const {schema, idSchema, uiSchema, disabled, readonly, autofocus, onBlur} = this.props;
const {items} = this.state;
const {widgets, definitions} = this.props.registry;
const {widgets, definitions, formContext} = this.props.registry;
const itemsSchema = retrieveSchema(schema.items, definitions);
const enumOptions = optionsList(itemsSchema);
const {widget="select", ...options} = {...getUiOptions(uiSchema), enumOptions};
Expand All @@ -347,6 +349,7 @@ class ArrayField extends Component {
value={items}
disabled={disabled}
readonly={readonly}
formContext={formContext}
autofocus={autofocus}/>
);
}
Expand All @@ -355,7 +358,7 @@ class ArrayField extends Component {
const {schema, uiSchema, idSchema, name, disabled, readonly, autofocus, onBlur} = this.props;
const title = schema.title || name;
const {items} = this.state;
const {widgets} = this.props.registry;
const {widgets, formContext} = this.props.registry;
const {widget="files", ...options} = getUiOptions(uiSchema);
const Widget = getWidget(schema, widget, widgets);
return (
Expand All @@ -370,6 +373,7 @@ class ArrayField extends Component {
value={items}
disabled={disabled}
readonly={readonly}
formContext={formContext}
autofocus={autofocus}/>
);
}
Expand Down
60 changes: 59 additions & 1 deletion test/FormContext_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ describe("FormContext", () => {
const {node} = createFormComponent({
schema: {
type: "object",
title: "A title",
properties: {
prop: {
type: "string"
Expand All @@ -81,6 +80,26 @@ describe("FormContext", () => {
.to.exist;
});

it("should be passed to ArrayTemplateField", () => {
function CustomArrayTemplateField({formContext}) {
return <div id={formContext.foo}/>;
}

const {node} = createFormComponent({
schema: {
type: "array",
items: {
type: "string"
}
},
ArrayFieldTemplate: CustomArrayTemplateField,
formContext
});

expect(node.querySelector("#" + formContext.foo))
.to.exist;
});

it("should be passed to custom TitleField", () => {
const fields = {TitleField: CustomComponent};

Expand Down Expand Up @@ -114,4 +133,43 @@ describe("FormContext", () => {
expect(node.querySelector("#" + formContext.foo))
.to.exist;
});


it("should be passed to multiselect", () => {
const widgets = {SelectWidget: CustomComponent};
const {node} = createFormComponent({
schema: {
type: "array",
items: {
type: "string",
enum: ["foo"],
enumNames: ["bar"]
},
uniqueItems: true
},
widgets,
formContext
});

expect(node.querySelector("#" + formContext.foo))
.to.exist;
});

it("should be passed to files array", () => {
const widgets = {FileWidget: CustomComponent};
const {node} = createFormComponent({
schema: {
type: "array",
items: {
type: "string",
format: "data-url"
}
},
widgets,
formContext
});

expect(node.querySelector("#" + formContext.foo))
.to.exist;
});
});