fix double initSelection call in select2

This commit is contained in:
vitalets 2013-09-21 21:21:48 +04:00
parent cc72d35664
commit 3166073666
2 changed files with 16 additions and 7 deletions
CHANGELOG.txt
src/inputs/select2

@ -3,6 +3,7 @@ X-editable changelog
Version 1.5.0 wip
----------------------------
[enh] update select2 to 3.4.3 (vitalets)
[enh #343] Bootstrap 3 support (vitalets)

@ -1,7 +1,7 @@
/**
Select2 input. Based on amazing work of Igor Vaynberg https://github.com/ivaynberg/select2.
Please see [original select2 docs](http://ivaynberg.github.com/select2) for detailed description and options.
Compatible **select2 version is 3.4.1**!
You should manually download and include select2 distributive:
<link href="select2/select2.css" rel="stylesheet" type="text/css"></link>
@ -143,8 +143,10 @@ $(function(){
render: function() {
this.setClass();
//apply select2
this.$input.select2(this.options.select2);
//can not apply select2 here as it calls initSelection
//over input that does not have correct value yet.
//apply select2 only in value2input
//this.$input.select2(this.options.select2);
//when data is loaded via ajax, we need to know when it's done to populate listData
if(this.isRemote) {
@ -208,7 +210,13 @@ $(function(){
*/
//for remote source just set value, text is updated by initSelection
this.$input.val(value).trigger('change', true); //second argument needed to separate initial change from user's click (for autosubmit)
if(!this.$input.data('select2')) {
this.$input.val(value);
this.$input.select2(this.options.select2);
} else {
//second argument needed to separate initial change from user's click (for autosubmit)
this.$input.val(value).trigger('change', true);
}
//if remote source AND no user's initSelection provided --> try to use element's text
if(this.isRemote && !this.isMultiple && !this.options.select2.initSelection) {