Skip to content

Commit

Permalink
Migrate SelectInput
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Jun 15, 2019
1 parent 15bfb44 commit 87baf9b
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 162 deletions.
10 changes: 7 additions & 3 deletions packages/ra-ui-materialui/src/input/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import get from 'lodash/get';
import MenuItem from '@material-ui/core/MenuItem';
import { withStyles, createStyles } from '@material-ui/core/styles';
import compose from 'recompose/compose';
import { addField, translate, FieldTitle } from 'ra-core';
import { addField, translate, FieldTitle, ValidationError } from 'ra-core';
import ResettableTextField from './ResettableTextField';

const sanitizeRestProps = ({
Expand Down Expand Up @@ -209,14 +209,15 @@ export class SelectInput extends Component {
options,
resource,
source,
helperText,
...rest
} = this.props;
if (typeof meta === 'undefined') {
throw new Error(
"The SelectInput component wasn't called within a redux-form <Field>. Did you decorate it and forget to add the addField prop to your component? See https://marmelab.com/react-admin/Inputs.html#writing-your-own-input-component for details."
);
}
const { touched, error, helperText = false } = meta;
const { touched, error } = meta;

return (
<ResettableTextField
Expand All @@ -235,7 +236,10 @@ export class SelectInput extends Component {
className={`${classes.input} ${className}`}
clearAlwaysVisible
error={!!(touched && error)}
helperText={(touched && error) || helperText}
helperText={touched && error
? <ValidationError error={error} />
: helperText
}
{...options}
{...sanitizeRestProps(rest)}
onChange={this.handleChange}
Expand Down
Loading

0 comments on commit 87baf9b

Please sign in to comment.