Skip to content

Commit ace4712

Browse files
author
jonisaa
committed
- Update server api response, deleted react-select, modified Lookup and Select - Modified componentsSelect/Lookup text to generate a Select/Lookup which consumes the api
1 parent 71417bb commit ace4712

File tree

6 files changed

+27
-24
lines changed

6 files changed

+27
-24
lines changed

demo/Server.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ let router = new Router();
2020

2121
router.get("/api/languages", (request, response) => {
2222
const arr = [
23-
"español",
24-
"english",
25-
"deutsch"
26-
]
23+
{
24+
value: "español",
25+
label: "Español"
26+
},
27+
{
28+
value: "english",
29+
label: "English"
30+
},
31+
{
32+
value: "deutsch",
33+
label: "Deutsch"
34+
}
35+
];
2736

2837
response.status(200).json(arr);
2938
});

demo/presets/componentsLookup.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
component: "Select",
4444
options: {
4545
"url": "/api/languages",
46-
"label": "Languages",
46+
"label": "label",
4747
"value": "value"
4848
}
4949
}

demo/presets/componentsSelect.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
component: "Select",
6666
options: {
6767
"url": "/api/languages",
68-
"label": "Languages",
68+
"label": "label",
6969
"value": "value"
7070
}
7171
}

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"react": "^15.1.0",
3333
"react-bootstrap": "^0.30.0",
3434
"react-dom": "^15.2.1",
35-
"react-select": "^0.9.1",
3635
"react-select-plus": "^1.0.0-beta14.patch1",
3736
"react-widgets": "^3.4.2",
3837
"redux-autoform-utils": "^1.0.3",

src/components/fieldComponents/Lookup.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Select from 'react-select-plus';
55
class Lookup extends Component {
66
fetchItems = () => {
77
const { options } = this.props;
8-
8+
99
return fetch(options.url)
1010
.then(response => response.json())
1111
.then(json => {
@@ -28,11 +28,11 @@ class Lookup extends Component {
2828
)
2929

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

3333
return (
3434
<FormGroup {...formGroupProps}>
35-
<Select.Async {...selectProps}/>
35+
<Select.Async {...selectProps} loadOptions={this.fetchItems}/>
3636
</FormGroup>
3737
)
3838
}

src/components/fieldComponents/Select.js

+9-14
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,27 @@ 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 = {
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-
};
5142

5243
if (options && Array.isArray(options)) {
53-
console.info("Render normal select!");
54-
5544
return (
5645
<Input componentClass="select" {...this.props}>
5746
{ this.getOptions() }
5847
</Input>
5948
);
6049

6150
} else if (options.url) {
62-
console.info("Async props: " + JSON.stringify(selectProps));
63-
console.info("Render async select!");
51+
let selectProps = {
52+
value,
53+
name,
54+
onChange,
55+
onBlur: (event) => onBlur(),
56+
valueKey: options.value? options.value : 'value',
57+
labelKey: options.label? options.label : 'label'
58+
};
6459

6560
return (
6661
<FormGroup {...formGroupProps}>
67-
<ReactSelect.Async {...selectProps}/>
62+
<ReactSelect.Async {...selectProps} loadOptions={this.fetchItems}/>
6863
</FormGroup>
6964
);
7065
}

0 commit comments

Comments
 (0)