diff --git a/packages/ra-ui-materialui/src/input/BooleanInput.js b/packages/ra-ui-materialui/src/input/BooleanInput.js
index b3282eb3329..9b950dd95a2 100644
--- a/packages/ra-ui-materialui/src/input/BooleanInput.js
+++ b/packages/ra-ui-materialui/src/input/BooleanInput.js
@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import FormGroup from '@material-ui/core/FormGroup';
+import FormHelperText from '@material-ui/core/FormHelperText';
import Switch from '@material-ui/core/Switch';
import { addField, FieldTitle } from 'ra-core';
@@ -23,6 +24,7 @@ export class BooleanInput extends Component {
resource,
options,
fullWidth,
+ meta,
...rest
} = this.props;
@@ -51,6 +53,13 @@ export class BooleanInput extends Component {
/>
}
/>
+ {meta.error
+ ? meta.error.map((error, index) => (
+
+ {error}
+
+ ))
+ : null}
);
}
diff --git a/packages/ra-ui-materialui/src/input/BooleanInput.spec.js b/packages/ra-ui-materialui/src/input/BooleanInput.spec.js
index f598465679f..ecc01920fa6 100644
--- a/packages/ra-ui-materialui/src/input/BooleanInput.spec.js
+++ b/packages/ra-ui-materialui/src/input/BooleanInput.spec.js
@@ -6,7 +6,9 @@ import { BooleanInput } from './BooleanInput';
describe('', () => {
it('should render as a mui Toggle', () => {
- const wrapper = shallow()
+ const wrapper = shallow(
+
+ )
.find('WithStyles(FormControlLabel)')
.shallow()
.dive();
@@ -16,7 +18,7 @@ describe('', () => {
it('should be checked if the value is true', () => {
const wrapper = shallow(
-
+
)
.find('WithStyles(FormControlLabel)')
.shallow()
@@ -26,7 +28,7 @@ describe('', () => {
it('should not be checked if the value is false', () => {
const wrapper = shallow(
-
+
)
.find('WithStyles(FormControlLabel)')
.shallow()
@@ -35,10 +37,42 @@ describe('', () => {
});
it('should not be checked if the value is undefined', () => {
- const wrapper = shallow()
+ const wrapper = shallow(
+
+ )
.find('WithStyles(FormControlLabel)')
.shallow()
.dive();
assert.equal(wrapper.find('WithStyles(Switch)').prop('checked'), false);
});
+
+ it('should displays errors', () => {
+ const wrapper = shallow(
+
+ )
+ .find('WithStyles(FormGroup)')
+ .shallow()
+ .dive();
+ assert.equal(wrapper.find('WithStyles(FormHelperText)').length, 2);
+ assert.equal(
+ wrapper
+ .find('WithStyles(FormHelperText)')
+ .at(0)
+ .children()
+ .text(),
+ 'foo'
+ );
+ assert.equal(
+ wrapper
+ .find('WithStyles(FormHelperText)')
+ .at(1)
+ .children()
+ .text(),
+ 'bar'
+ );
+ });
});