diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 38697fd..ee4fc22 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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) diff --git a/src/inputs/select2/select2.js b/src/inputs/select2/select2.js index d6342b9..5a401fd 100644 --- a/src/inputs/select2/select2.js +++ b/src/inputs/select2/select2.js @@ -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> @@ -142,9 +142,11 @@ $(function(){ $.extend(Constructor.prototype, { 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) { @@ -207,8 +209,14 @@ $(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) + //for remote source just set value, text is updated by initSelection + 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) { @@ -216,7 +224,7 @@ $(function(){ customText = this.options.select2.formatSelection; if(!customId && !customText) { var data = {id: value, text: $(this.options.scope).text()}; - this.$input.select2('data', data); + this.$input.select2('data', data); } } },