Skip to content

Commit

Permalink
Merge pull request #847 from RealHQ/master
Browse files Browse the repository at this point in the history
Fix issue with value object not being passed to handleRequired
  • Loading branch information
JedWatson committed Apr 26, 2016
2 parents bd55d8f + 6939cb2 commit 5fd9cf4
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,32 @@ const Select = React.createClass({
isLoading: false,
isOpen: false,
isPseudoFocused: false,
required: this.props.required && this.handleRequired(this.props.value, this.props.multi)
required: false,
};
},

componentWillMount () {
const valueArray = this.getValueArray(this.props.value);

if (this.props.required) {
this.setState({
required: this.handleRequired(valueArray[0], this.props.multi),
});
}
},

componentDidMount () {
if (this.props.autofocus) {
this.focus();
}
},

componentWillReceiveProps(nextProps) {
if (this.props.value !== nextProps.value && nextProps.required) {
const valueArray = this.getValueArray(nextProps.value);

if (nextProps.required) {
this.setState({
required: this.handleRequired(nextProps.value, nextProps.multi),
required: this.handleRequired(valueArray[0], nextProps.multi),
});
}
},
Expand Down Expand Up @@ -426,8 +438,7 @@ const Select = React.createClass({
return op[this.props.labelKey];
},

getValueArray () {
let value = this.props.value;
getValueArray (value) {
if (this.props.multi) {
if (typeof value === 'string') value = value.split(this.props.delimiter);
if (!Array.isArray(value)) {
Expand Down Expand Up @@ -482,19 +493,19 @@ const Select = React.createClass({
},

addValue (value) {
var valueArray = this.getValueArray();
var valueArray = this.getValueArray(this.props.value);
this.setValue(valueArray.concat(value));
},

popValue () {
var valueArray = this.getValueArray();
var valueArray = this.getValueArray(this.props.value);
if (!valueArray.length) return;
if (valueArray[valueArray.length-1].clearableValue === false) return;
this.setValue(valueArray.slice(0, valueArray.length - 1));
},

removeValue (value) {
var valueArray = this.getValueArray();
var valueArray = this.getValueArray(this.props.value);
this.setValue(valueArray.filter(i => i !== value));
this.focus();
},
Expand Down Expand Up @@ -829,7 +840,7 @@ const Select = React.createClass({
},

render () {
let valueArray = this.getValueArray();
let valueArray = this.getValueArray(this.props.value);
let options = this._visibleOptions = this.filterOptions(this.props.multi ? valueArray : null);
let isOpen = this.state.isOpen;
if (this.props.multi && !options.length && valueArray.length && !this.state.inputValue) isOpen = false;
Expand Down

0 comments on commit 5fd9cf4

Please sign in to comment.