Skip to content

Commit

Permalink
fix(widget): decouple getSuggestionDisplayValue to restore getting …
Browse files Browse the repository at this point in the history
…`getSuggestionValue` properly in `Autosuggest` component
  • Loading branch information
medfreeman committed Sep 12, 2017
1 parent 5dc11be commit 4c6f2c1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/Widgets/RelationControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class RelationControl extends Component {
this.didInitialSearch = true;
const suggestion = nextProps.queryHits.get(this.controlID);
if (suggestion && suggestion.length === 1) {
const { value, displayValue } = this.getSuggestionValues(suggestion[0]);
const value = this.getSuggestionValue(suggestion[0]);
this.props.onChange(value, { [nextProps.field.get('collection')]: { [value]: suggestion[0].data } });
const displayValue = this.getSuggestionDisplayValue(suggestion[0]);
this.setState({ displayValue });
}
}
Expand All @@ -64,8 +65,9 @@ class RelationControl extends Component {
};

onSuggestionSelected = (event, { suggestion }) => {
const { value, displayValue } = this.getSuggestionValues(suggestion);
const value = this.getSuggestionValue(suggestion);
this.props.onChange(value, { [this.props.field.get('collection')]: { [value]: suggestion.data } });
const displayValue = this.getSuggestionDisplayValue(suggestion);
this.setState({ displayValue });
};

Expand All @@ -81,11 +83,16 @@ class RelationControl extends Component {
this.props.clearSearch();
};

getSuggestionValues = (suggestion) => {
getSuggestionValue = (suggestion) => {
const { field } = this.props;
const valueField = field.get('valueField');
return suggestion.data[valueField];
};

getSuggestionDisplayValue = (suggestion) => {
const { field } = this.props;
const displayField = field.get('displayField');
return { value: suggestion.data[valueField], displayValue: suggestion.data[displayField] };
return suggestion.data[displayField];
};

renderSuggestion = (suggestion) => {
Expand Down

0 comments on commit 4c6f2c1

Please sign in to comment.