Skip to content

Commit 71417bb

Browse files
author
jonisaa
committed
#15 Adding data for Lookup preset, modified Select and Lookup components, Updated package.json to add react-select-plus
1 parent fb850fa commit 71417bb

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

demo/presets/componentsLookup.txt

+11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
{ value: 'option1', label: 'Option 1' },
3636
{ value: 'option2', label: 'Option 2' },
3737
]
38+
},
39+
{
40+
name: "Languages",
41+
displayName: "Languages",
42+
type: "string",
43+
component: "Select",
44+
options: {
45+
"url": "/api/languages",
46+
"label": "Languages",
47+
"value": "value"
48+
}
3849
}
3950
]
4051
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"react-bootstrap": "^0.30.0",
3434
"react-dom": "^15.2.1",
3535
"react-select": "^0.9.1",
36+
"react-select-plus": "^1.0.0-beta14.patch1",
3637
"react-widgets": "^3.4.2",
3738
"redux-autoform-utils": "^1.0.3",
3839
"underscore": "^1.8.3"

src/components/fieldComponents/Lookup.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component, PropTypes } from 'react';
22
import FormGroup from '../FormGroup';
3-
import Select from 'react-select';
3+
import Select from 'react-select-plus';
44

55
class Lookup extends Component {
66
fetchItems = () => {
@@ -27,7 +27,7 @@ class Lookup extends Component {
2727
</FormGroup>
2828
)
2929

30-
} else {
30+
} else if (options.url) {
3131
selectProps = { value, name, onChange, onBlur: (event) => onBlur(), loadOptions: this.fetchItems, valueKey: options.value? options.value : 'value', labelKey: options.label? options.label : 'label' };
3232

3333
return (
@@ -36,6 +36,8 @@ class Lookup extends Component {
3636
</FormGroup>
3737
)
3838
}
39+
40+
return false;
3941
}
4042
}
4143

src/components/fieldComponents/Select.js

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import FormGroup from '../FormGroup';
33
import Input from '../Input';
4-
import ReSelect from 'react-select';
4+
import ReactSelect from 'react-select-plus';
55
import fetch from 'isomorphic-fetch';
66

77
class Select extends Component {
@@ -39,18 +39,32 @@ class Select extends Component {
3939
render() {
4040
let { value, name, displayName, help, error, touched, onChange, onBlur, fieldLayout, options } = this.props;
4141
let formGroupProps = { error, touched, displayName, name, help, fieldLayout };
42-
let selectProps = { value, name, onChange, onBlur: (event) => onBlur(), loadOptions: this.fetchItems, valueKey: options.value? options.value : 'value', labelKey: options.label? options.label : 'label' };
42+
let selectProps = {
43+
value,
44+
name,
45+
onChange,
46+
onBlur: (event) => onBlur(),
47+
loadOptions: this.fetchItems,
48+
valueKey: options.value? options.value : 'value',
49+
labelKey: options.label? options.label : 'label'
50+
};
51+
52+
if (options && Array.isArray(options)) {
53+
console.info("Render normal select!");
4354

44-
if (!options.url && Array.isArray(options)) {
4555
return (
4656
<Input componentClass="select" {...this.props}>
4757
{ this.getOptions() }
4858
</Input>
4959
);
60+
5061
} else if (options.url) {
62+
console.info("Async props: " + JSON.stringify(selectProps));
63+
console.info("Render async select!");
64+
5165
return (
5266
<FormGroup {...formGroupProps}>
53-
<ReSelect.Async {...selectProps}/>
67+
<ReactSelect.Async {...selectProps}/>
5468
</FormGroup>
5569
);
5670
}

0 commit comments

Comments
 (0)