fixed too much recursion issue on selection JSX
This commit is contained in:
committed by
MrCasual
parent
bb4893c0a0
commit
72d1eb79a6
@ -25,13 +25,10 @@ function(
|
|||||||
(this.props.item !== undefined && prevProps.item !== undefined)
|
(this.props.item !== undefined && prevProps.item !== undefined)
|
||||||
&& (this.props.item.id !== prevProps.item.id)
|
&& (this.props.item.id !== prevProps.item.id)
|
||||||
) {
|
) {
|
||||||
jQuery('#'+this.refs.select.id).select2(
|
jQuery('#'+this.refs.select.id)
|
||||||
'val',
|
.val(this.props.item[this.props.field.name])
|
||||||
this.props.item[this.props.field.name]
|
.trigger('change');
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setupSelect2();
|
|
||||||
},
|
},
|
||||||
setupSelect2: function() {
|
setupSelect2: function() {
|
||||||
if(
|
if(
|
||||||
@ -53,7 +50,19 @@ function(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var hasRemoved = false;
|
||||||
|
select2.on('select2:unselecting', function(e) {
|
||||||
|
hasRemoved = true;
|
||||||
|
});
|
||||||
|
select2.on('select2:opening', function(e) {
|
||||||
|
if(hasRemoved === true) {
|
||||||
|
hasRemoved = false;
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
select2.on('change', this.handleChange);
|
select2.on('change', this.handleChange);
|
||||||
|
|
||||||
select2.select2(
|
select2.select2(
|
||||||
'val',
|
'val',
|
||||||
this.props.item[this.props.field.name]
|
this.props.item[this.props.field.name]
|
||||||
@ -77,7 +86,7 @@ function(
|
|||||||
handleChange: function(e) {
|
handleChange: function(e) {
|
||||||
if(this.props.onValueChange !== undefined) {
|
if(this.props.onValueChange !== undefined) {
|
||||||
if(this.props.field.multiple) {
|
if(this.props.field.multiple) {
|
||||||
value = jQuery('#'+this.refs.select.id).select2('val');
|
value = jQuery('#'+this.refs.select.id).val();
|
||||||
} else {
|
} else {
|
||||||
value = e.target.value;
|
value = e.target.value;
|
||||||
}
|
}
|
||||||
@ -88,7 +97,6 @@ function(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var options = this.state.items.map(function(item, index) {
|
var options = this.state.items.map(function(item, index) {
|
||||||
@ -114,7 +122,6 @@ function(
|
|||||||
ref="select"
|
ref="select"
|
||||||
placeholder={ this.props.field.placeholder }
|
placeholder={ this.props.field.placeholder }
|
||||||
multiple={ this.props.field.multiple }
|
multiple={ this.props.field.multiple }
|
||||||
onChange={ this.handleChange }
|
|
||||||
defaultValue={ default_value }
|
defaultValue={ default_value }
|
||||||
>{ options }</select>
|
>{ options }</select>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user