Skip to content

Commit

Permalink
Document auto translation
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Apr 25, 2017
1 parent 2c482d0 commit 767e15d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 19 additions & 1 deletion docs/Inputs.md
Expand Up @@ -754,12 +754,14 @@ const choices = [
];
```

However, in some cases (e.g. inside a `<ReferenceInput>`), you may not want the choice to be translated. In that case, set the `translateChoice` prop to false.
However, in some cases, you may not want the choice to be translated. In that case, set the `translateChoice` prop to false.

```js
<SelectInput source="gender" choices={choices} translateChoice={false}/>
```

Note that `translateChoice` is set to false when `<SelectInput>` is a child of `<ReferenceInput>`.

Lastly, use the `options` attribute if you want to override any of Material UI's `<SelectField>` attributes:

{% raw %}
Expand Down Expand Up @@ -814,6 +816,22 @@ const choices = [
<SelectArrayInput source="categories" choices={choices} optionText="plural_name" optionValue="_id" />
```

The choices are translated by default, so you can use translation identifiers as choices:

```js
const choices = [
{ id: 'books', name: 'myroot.category.books' },
{ id: 'sport', name: 'myroot.category.sport' },
];
```

However, in some cases, you may not want the choice to be translated. In that case, set the `translateChoice` prop to false.

```js
<SelectArrayInput source="gender" choices={choices} translateChoice={false}/>
```

Note that `translateChoice` is set to false when `<SelectArrayInput>` is a child of `<ReferenceArrayInput>`.

Lastly, use the `options` attribute if you want to override any of the `<ChipInput>` attributes:

Expand Down
4 changes: 3 additions & 1 deletion src/mui/input/SelectArrayInput.js
Expand Up @@ -93,7 +93,9 @@ export class SelectArrayInput extends Component {
if (this.props.choices && this.props.choices.length > 0) {
return this.getChoices().filter(choice => values.includes(choice.value));
}
return [];
return values.map(value => ({
value, text: value, // FIXME will show ids instead of labels on first paint, with no redraw
}));
};

getChoices = () => {
Expand Down

0 comments on commit 767e15d

Please sign in to comment.