Skip to content

Commit

Permalink
Fix issue with value object not being passed to handleRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hite committed Mar 23, 2016
1 parent 18758f7 commit 6939cb2
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 @@ -128,20 +128,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 @@ -405,8 +417,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 @@ -461,19 +472,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 @@ -779,7 +790,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 6939cb2

Please sign in to comment.