Skip to content

Commit dddc99c

Browse files
committed
Removes the Languages API, adds documentation for the URL in the Lookup #22 #30
1 parent ac902aa commit dddc99c

File tree

4 files changed

+31
-35
lines changed

4 files changed

+31
-35
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ Specific metadata for the `Lookup` component. Common metadata is not listed.
149149

150150
Metadata | Description
151151
--- | ---
152-
options | The options to display. Options are an array of objects with two properties: **value**: The actual value that is stored in the model. **text**: What is displayed to the user
152+
options (array) | The options to display. Options is an array of objects with two properties: **value**: The actual value that is stored in the model; **label**: What is displayed to the user
153+
options (object) | The options to display. Options is an object containing three properties: **url**: The URL to call for data. This call should return an array of objects. **valueKey**: In the resulting Array, this is the name of the property that should contain the actual value. **labelKey**: In the resulting Array, this is the name of the property that should contain the label.
153154

154155
[Lookup demo](https://redux-autoform.github.io/redux-autoform-bootstrap-ui/demo.html?preset=componentsLookup).
155156

demo/Server.js

-19
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,6 @@ let app = express();
3333

3434
let router = new Router();
3535

36-
router.get("/api/languages", (request, response) => {
37-
const arr = [
38-
{
39-
value: "español",
40-
label: "Español"
41-
},
42-
{
43-
value: "english",
44-
label: "English"
45-
},
46-
{
47-
value: "deutsch",
48-
label: "Deutsch"
49-
}
50-
];
51-
52-
response.status(200).json(arr);
53-
});
54-
5536
router.post("/upload", (request, response) => {
5637

5738
upload.array("fileData")(request, response, (err) => {

demo/presets/componentsLookup.txt

+7-6
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@
3737
]
3838
},
3939
{
40-
name: "Languages",
41-
displayName: "Languages",
40+
name: "Url",
41+
displayName: "Url",
4242
type: "string",
43-
component: "Select",
43+
component: "Lookup",
44+
help: "Lists the React project open-issues",
4445
options: {
45-
"url": "/api/languages",
46-
"label": "label",
47-
"value": "value"
46+
url: "https://api.github.com/repos/facebook/react/issues",
47+
valueKey: "id",
48+
labelKey: "title"
4849
}
4950
}
5051
]

src/components/field/Lookup.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1-
import React, { Component, PropTypes } from 'react';
1+
import React, {Component, PropTypes} from 'react';
22
import FormGroup from '../common/FormGroup';
33
import Select from 'react-select-plus';
44

55
class Lookup extends Component {
66
fetchItems = () => {
7-
const { options } = this.props;
8-
7+
const {options} = this.props;
8+
99
return fetch(options.url)
1010
.then(response => response.json())
1111
.then(json => {
12-
return { options: json }
12+
return {options: json}
1313
});
1414
};
1515

1616
render() {
17-
let { value, name, displayName, help, error, touched, onChange, onBlur, options, fieldLayout } = this.props;
18-
let formGroupProps = { error, touched, displayName, name, help, fieldLayout};
17+
let {value, name, displayName, help, error, touched, onChange, onBlur, options, fieldLayout} = this.props;
18+
let formGroupProps = {error, touched, displayName, name, help, fieldLayout};
1919
let selectProps;
2020

21-
if (!options.url && Array.isArray(options)) {
22-
selectProps = { options, value, name, onChange, onBlur: (event) => onBlur() };
21+
if (Array.isArray(options)) {
22+
selectProps = {
23+
options,
24+
value,
25+
name,
26+
onChange,
27+
onBlur: (event) => onBlur()
28+
};
2329

2430
return (
2531
<FormGroup {...formGroupProps}>
@@ -28,7 +34,14 @@ class Lookup extends Component {
2834
)
2935

3036
} else if (options.url) {
31-
selectProps = { value, name, onChange, onBlur: (event) => onBlur(), valueKey: options.value? options.value : 'value', labelKey: options.label? options.label : 'label' };
37+
selectProps = {
38+
value,
39+
name,
40+
onChange,
41+
onBlur: (event) => onBlur(),
42+
valueKey: options.valueKey || 'value',
43+
labelKey: options.labelKey || 'label'
44+
};
3245

3346
return (
3447
<FormGroup {...formGroupProps}>

0 commit comments

Comments
 (0)