Skip to content

Commit

Permalink
ver. 0.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
光弘 committed Sep 5, 2018
1 parent 66456dd commit d040fe7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.4

* `CHANGED` pass other data item to Option

## 0.4.0

* `CHANGED` adapt React 16
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uxcore-select-form-field",
"version": "0.4.3",
"version": "0.4.4",
"description": "uxcore-select-form-field component for uxcore.",
"repository": "https://github.com/uxcore/uxcore-select-form-field.git",
"author": "eternalsky",
Expand Down
53 changes: 31 additions & 22 deletions src/SelectFormField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class SelectFormField extends FormField {
constructor(props) {
super(props);
const me = this;
const { jsxdata } = props;
assign(me.state, {
data: processData(props.jsxdata),
prevPropsData: props.jsxdata,
data: processData(jsxdata),
prevPropsData: jsxdata,
});
}

Expand Down Expand Up @@ -131,18 +132,20 @@ class SelectFormField extends FormField {
_generateOptionsFromData() {
const me = this;
const values = me.state.data;
const children = me.props.children;
const { children } = me.props;
if (!values.length) {
// console.warn("You need to pass data to initialize Select.");
if (children) {
return children;
}
}
const arr = values.map(item =>
(<Option key={item.value} title={item.text} disabled={item.disabled}>
{item.text}
</Option>),
);
const arr = values.map((item) => {
const { value, text, ...others } = item;
return (
<Option key={value} title={text} {...others}>
{item.text}
</Option>
);
});
return arr;
}

Expand All @@ -152,11 +155,12 @@ class SelectFormField extends FormField {
*/
getFullData() {
const { data, value } = this.state;
if(Array.isArray(value)) {
return value.map(selectItem => find(data, (item) => item.value === selectItem.key));
if (Array.isArray(value)) {
return value.map(selectItem => find(data, item => item.value === selectItem.key));
}
return find(data, (item) => item.value === value);
return find(data, item => item.value === value);
}

/**
* transfer 'a' to { key: 'a' }
* transfer ['a'] to [{ key: 'a' }]
Expand All @@ -174,7 +178,7 @@ class SelectFormField extends FormField {
return {
key: newValue,
};
} else if (newValue instanceof Array) {
} if (newValue instanceof Array) {
return newValue.map((item) => {
if (typeof item === 'string') {
return {
Expand Down Expand Up @@ -248,9 +252,11 @@ class SelectFormField extends FormField {
}
/* eslint-disable no-underscore-dangle */
/* used in SearchFormField */
arr.push(<Select {...options}>
{me._generateOptionsFromData()}
</Select>);
arr.push(
<Select {...options}>
{me._generateOptionsFromData()}
</Select>,
);
/* eslint-enable no-underscore-dangle */
} else if (mode === Constants.MODE.VIEW) {
let str = '';
Expand Down Expand Up @@ -281,7 +287,11 @@ class SelectFormField extends FormField {
});
}
}
arr.push(<span key="select">{str}</span>);
arr.push(
<span key="select">
{str}
</span>,
);
}
return arr;
}
Expand Down Expand Up @@ -318,11 +328,10 @@ SelectFormField.defaultProps = assign({}, FormField.defaultProps, {
searchDelay: 100,
beforeFetch: obj => obj,
afterFetch: obj => obj,
fitResponse: response =>
({
content: response.content || response,
success: response.success === undefined ? true : response.success,
}),
fitResponse: response => ({
content: response.content || response,
success: response.success === undefined ? true : response.success,
}),
jsxshowSearch: true,
jsxallowClear: false,
jsxtags: false,
Expand Down
10 changes: 4 additions & 6 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ const processData = (data) => {
let values = [];
if (typeof data === 'object' && !(data instanceof Array)) {
const keys = Object.keys(data);
values = keys.map(key =>
({
value: key,
text: data[key],
}),
);
values = keys.map(key => ({
value: key,
text: data[key],
}));
} else {
values = data;
}
Expand Down

0 comments on commit d040fe7

Please sign in to comment.