diff --git a/src/components/EditorWidgets/Relation/RelationControl.js b/src/components/EditorWidgets/Relation/RelationControl.js index 8cb2d6519753..d901d85af395 100644 --- a/src/components/EditorWidgets/Relation/RelationControl.js +++ b/src/components/EditorWidgets/Relation/RelationControl.js @@ -90,7 +90,14 @@ class RelationControl extends Component { renderSuggestion = (suggestion) => { const { field } = this.props; - const valueField = field.get('valueField'); + const valueField = field.get('displayFields').toJS() || field.get('valueField'); + if (Array.isArray(valueField)) { + return ( + + {valueField.map(key => {suggestion.data[key]}{' '})} + + ); + } return {suggestion.data[valueField]}; }; diff --git a/website/site/content/docs/widgets/relation.md b/website/site/content/docs/widgets/relation.md index c431884fe089..aea4dc9d6398 100644 --- a/website/site/content/docs/widgets/relation.md +++ b/website/site/content/docs/widgets/relation.md @@ -13,6 +13,7 @@ The relation widget allows you to reference items from another collection. It pr - **Options:** - `default`: accepts any widget data type; defaults to an empty string - `collection`: (**required**) name of the collection being referenced (string) + - `displayFields`: list of one or more names of fields in the referenced collection that will render in the autocomplete menu of the control. The value field is used by default. - `searchFields`: (**required**) list of one or more names of fields in the referenced collection to search for the typed value - `valueField`: (**required**) name of the field from the referenced collection whose value will be stored for the relation - **Example** (assuming a separate "authors" collection with "name" and "twitterHandle" fields): @@ -22,7 +23,8 @@ The relation widget allows you to reference items from another collection. It pr name: "author" widget: "relation" collection: "authors" + displayFields: ["twitterHandle", "followerCount"] searchFields: ["name", "twitterHandle"] valueField: "name" ``` - The generated UI input will search the authors collection by name and twitterHandle as the user types. On selection, the author name will be saved for the field. + The generated UI input will search the authors collection by name and twitterHandle as the user types. Each collection will be represented by the author's handle and follower count. On selection, the author name will be saved for the field.