Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,18 @@ labelStyle: {
```

You can also pass `insertDividers` value as `true` or `false` to get the divider or not. Default value for `insertDividers` is true.

### Limit list items

There is a prop named `maxItems`:

```jsx
<EmbeddedArrayField source="links" maxItems={3}>
<UrlField source="url" />
<TextField source="context" />
<EmbeddedArrayField source="metadata" maxItems={5}>
<TextField source="name" />
<TextField source="value" />
</EmbeddedArrayField>
</EmbeddedArrayField>
```
10 changes: 9 additions & 1 deletion src/mui/input/EmbeddedArrayInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class EmbeddedArrayInput extends Component {
labelContainerStyle: PropTypes.object,
labelStyle: PropTypes.object,
insertDividers: PropTypes.bool,
maxItems: PropTypes.number,
maxItemsCount: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -86,6 +88,7 @@ export class EmbeddedArrayInput extends Component {
labelAdd: 'aor.input.embedded_array.add',
labelRemove: 'aor.input.embedded_array.remove',
insertDividers: true,
maxItemsCount: true,
actionsContainerStyle: {
clear: 'both',
margin: '1em',
Expand Down Expand Up @@ -182,8 +185,12 @@ export class EmbeddedArrayInput extends Component {
actionsContainerStyle,
innerContainerStyle,
insertDividers,
maxItems,
maxItemsCount,
} = this.props;
const createItem = () => items.push();
const isMaxItemsReached = () => {return (maxItems && maxItems === items.length) ? true : false};
const showMaxItemsCount = () => {return (maxItems && maxItemsCount) ? ' ('+items.length+'/'+maxItems+')' : '';} ;

return (
<div className="EmbeddedArrayInputContainer" style={style}>
Expand Down Expand Up @@ -212,10 +219,11 @@ export class EmbeddedArrayInput extends Component {
{allowAdd &&
!readOnly &&
!disabled &&
!isMaxItemsReached() &&
<FlatButton
primary
icon={<ContentAdd />}
label={translate(labelAdd, { _: 'Add' })}
label={translate(labelAdd, { _: 'Add' })+showMaxItemsCount()}
onClick={createItem}
/>}
</div>
Expand Down