Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error thrown by ChipInput component generated by AutocompleteArrayInput #2861

Merged
merged 2 commits into from
Feb 22, 2019
Merged
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions packages/ra-ui-materialui/src/input/AutocompleteArrayInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,27 @@ const styles = theme => ({
export class AutocompleteArrayInput extends React.Component {
state = {
dirty: false,
inputValue: null,
inputValue: [],
searchText: '',
suggestions: [],
};

inputEl = null;

getInputValue = inputValue => (inputValue === '' ? [] : inputValue);
tiagoschenkel marked this conversation as resolved.
Show resolved Hide resolved

componentWillMount() {
this.setState({
inputValue: this.props.input.value,
inputValue: this.getInputValue(this.props.input.value),
suggestions: this.props.choices,
});
}

componentWillReceiveProps(nextProps) {
const { choices, input, inputValueMatcher } = nextProps;
if (!isEqual(input.value, this.state.inputValue)) {
if (!isEqual(this.getInputValue(input.value), this.state.inputValue)) {
this.setState({
inputValue: input.value,
inputValue: this.getInputValue(input.value),
dirty: false,
suggestions: this.props.choices,
});
Expand Down Expand Up @@ -245,7 +247,7 @@ export class AutocompleteArrayInput extends React.Component {
onUpdateInput={onChange}
onAdd={this.handleAdd}
onDelete={this.handleDelete}
value={input.value}
value={this.getInputValue(input.value)}
inputRef={storeInputRef}
error={touched && error}
helperText={touched && error && helperText}
Expand Down