Autocomplete fixes #218

This commit is contained in:
orangemug
2018-01-19 11:50:23 +00:00
parent 2b382a9946
commit a33d1b819c
2 changed files with 66 additions and 80 deletions

View File

@@ -58,11 +58,22 @@ class AddModal extends React.Component {
componentWillUpdate(nextProps, nextState) {
// Check if source is valid for new type
const availableSources = this.getSources(nextState.type);
const oldType = this.state.type;
const newType = nextState.type;
const availableSourcesOld = this.getSources(oldType);
const availableSourcesNew = this.getSources(newType);
if(
this.state.source !== ""
&& availableSources.indexOf(this.state.source) < 0
// Type has changed
oldType !== newType
&& this.state.source !== ""
// Was a valid source previously
&& availableSourcesOld.indexOf(this.state.source) > -1
// And is not a valid source now
&& availableSourcesNew.indexOf(nextState.source) < 0
) {
// Clear the source
this.setState({
source: ""
});