Skip to content

Commit

Permalink
Not trigger onChange for initial render (55)
Browse files Browse the repository at this point in the history
rkit committed Nov 30, 2016
1 parent 0b7379e commit 261dc2c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/Select2.js
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ export default class Select2 extends Component {
super(props);
this.el = null;
this.forceUpdateValue = false;
this.initialRender = true;
}

componentDidMount() {
@@ -54,6 +55,7 @@ export default class Select2 extends Component {
}

componentWillReceiveProps(nextProps) {
this.initialRender = false;
this.updSelect2(nextProps);
}

@@ -104,7 +106,17 @@ export default class Select2 extends Component {
const currentValue = multiple ? this.el.val() || [] : this.el.val();

if (!shallowEqualFuzzy(currentValue, newValue) || this.forceUpdateValue) {
const onChange = this.props.onChange;

if (this.initialRender && onChange) {
this.el.off(`change.${namespace}`);
}

this.el.val(newValue).trigger('change');

if (this.initialRender && onChange) {
this.el.on(`change.${namespace}`, onChange);
}
this.forceUpdateValue = false;
}
}

0 comments on commit 261dc2c

Please sign in to comment.