Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Fixes #600
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunkat committed May 24, 2017
1 parent 5d697c3 commit 55a35c0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
51 changes: 39 additions & 12 deletions src/components/widget/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ class List extends Component {
}
}

componentDidUpdate(prevProps){
const {isInputEmpty} = this.props;

if(isInputEmpty && prevProps.isInputEmpty !== isInputEmpty) {

this.setState({
prevValue: ''
});

}
}

handleFocus = () => {
const {
properties, dispatch, dataId, rowId, tabId, windowType,
Expand Down Expand Up @@ -57,19 +69,33 @@ class List extends Component {
} = this.props;
const {prevValue} = this.state;

if(lookupList){
if( prevValue !== option[Object.keys(option)[0]] ) {
onChange(properties[0].field, option);

this.setState({
selectedItem: option,
prevValue: option[Object.keys(option)[0]]
});
setNextProperty(mainProperty[0].field);
if( prevValue !== option[Object.keys(option)[0]] ) {
if(lookupList){
onChange(properties[0].field, option);

this.setState({
selectedItem: option,
prevValue: option[Object.keys(option)[0]]
});
setNextProperty(mainProperty[0].field);
} else {
onChange(option);
}
} else {
onChange(option);
}
}
}

handleAutoSelect = (option) => {
const {
onChange, properties, setNextProperty, mainProperty
} = this.props;

onChange(properties[0].field, option);

this.setState({
selectedItem: option,
prevValue: option[Object.keys(option)[0]]
});
setNextProperty(mainProperty[0].field);
}

render() {
Expand All @@ -86,6 +112,7 @@ class List extends Component {
loading={loading}
onFocus={this.handleFocus}
onSelect={option => this.handleSelect(option)}
autoSelect={option => this.handleAutoSelect(option)}
rank={rank}
readonly={readonly}
defaultValue={defaultValue}
Expand Down
29 changes: 20 additions & 9 deletions src/components/widget/List/RawList.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,14 @@ class RawList extends Component {
}

handleFocus = (e) => {
const {lookupList} = this.props;
if(lookupList) {
e.preventDefault();
const {onFocus, doNotOpenOnFocus} = this.props;
e.preventDefault();
const {onFocus, doNotOpenOnFocus} = this.props;

onFocus && onFocus();
onFocus && onFocus();

!doNotOpenOnFocus && this.setState({
isOpen: true
})
}
!doNotOpenOnFocus && this.setState({
isOpen: true
})
}

handleChange = (e) => {
Expand All @@ -182,6 +179,20 @@ class RawList extends Component {
}, () => this.handleBlur())
}

handleAutoSelect = (option) => {
const {autoSelect} = this.props;

if(option){
autoSelect(option);
}else{
autoSelect(null);
}

this.setState({
selected: (option || 0)
}, () => this.handleBlur())
}

handleSwitch = (option) => {
this.setState({
selected: (option || 0)
Expand Down
3 changes: 2 additions & 1 deletion src/components/widget/Lookup/Lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Lookup extends Component {
const {defaultValue} = this.props;
const {property} = this.state;

const objectValue = property && getItemsByProperty(
const objectValue = property && getItemsByProperty(
defaultValue, 'field', property
)[0].value;

Expand Down Expand Up @@ -191,6 +191,7 @@ class Lookup extends Component {
mainProperty={[item]}
blur={!property?true:false}
readonly={disabled}
isInputEmpty={isInputEmpty}
/>
</div>
}
Expand Down

0 comments on commit 55a35c0

Please sign in to comment.