fix double initSelection call in select2
This commit is contained in:
@ -3,6 +3,7 @@ X-editable changelog
|
|||||||
|
|
||||||
Version 1.5.0 wip
|
Version 1.5.0 wip
|
||||||
----------------------------
|
----------------------------
|
||||||
|
[enh] update select2 to 3.4.3 (vitalets)
|
||||||
[enh #343] Bootstrap 3 support (vitalets)
|
[enh #343] Bootstrap 3 support (vitalets)
|
||||||
|
|
||||||
|
|
||||||
|
16
src/inputs/select2/select2.js
vendored
16
src/inputs/select2/select2.js
vendored
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
Select2 input. Based on amazing work of Igor Vaynberg https://github.com/ivaynberg/select2.
|
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.
|
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:
|
You should manually download and include select2 distributive:
|
||||||
|
|
||||||
<link href="select2/select2.css" rel="stylesheet" type="text/css"></link>
|
<link href="select2/select2.css" rel="stylesheet" type="text/css"></link>
|
||||||
@ -143,8 +143,10 @@ $(function(){
|
|||||||
render: function() {
|
render: function() {
|
||||||
this.setClass();
|
this.setClass();
|
||||||
|
|
||||||
//apply select2
|
//can not apply select2 here as it calls initSelection
|
||||||
this.$input.select2(this.options.select2);
|
//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
|
//when data is loaded via ajax, we need to know when it's done to populate listData
|
||||||
if(this.isRemote) {
|
if(this.isRemote) {
|
||||||
@ -208,7 +210,13 @@ $(function(){
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//for remote source just set value, text is updated by initSelection
|
//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 remote source AND no user's initSelection provided --> try to use element's text
|
||||||
if(this.isRemote && !this.isMultiple && !this.options.select2.initSelection) {
|
if(this.isRemote && !this.isMultiple && !this.options.select2.initSelection) {
|
||||||
|
Reference in New Issue
Block a user