fix first char being lost. fixes #196
This commit is contained in:
parent
207139bc12
commit
213d281ece
40
select2.js
40
select2.js
@ -1720,8 +1720,14 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
// single
|
// single
|
||||||
opening: function () {
|
opening: function () {
|
||||||
var el, range;
|
var el, range, len;
|
||||||
|
|
||||||
|
if (this.opts.minimumResultsForSearch >= 0) {
|
||||||
|
this.showSearch(true);
|
||||||
|
}
|
||||||
|
|
||||||
this.parent.opening.apply(this, arguments);
|
this.parent.opening.apply(this, arguments);
|
||||||
|
|
||||||
if (this.showSearchInput !== false) {
|
if (this.showSearchInput !== false) {
|
||||||
// IE appends focusser.val() at the end of field :/ so we manually insert it at the beginning using a range
|
// IE appends focusser.val() at the end of field :/ so we manually insert it at the beginning using a range
|
||||||
// all other browsers handle this just fine
|
// all other browsers handle this just fine
|
||||||
@ -1729,13 +1735,16 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.search.val(this.focusser.val());
|
this.search.val(this.focusser.val());
|
||||||
}
|
}
|
||||||
this.search.focus();
|
this.search.focus();
|
||||||
// in IE we have to move the cursor to the end after focussing, otherwise it will be at the beginning and
|
// move the cursor to the end after focussing, otherwise it will be at the beginning and
|
||||||
// new text will appear *before* focusser.val()
|
// new text will appear *before* focusser.val()
|
||||||
el = this.search.get(0);
|
el = this.search.get(0);
|
||||||
if (el.createTextRange) {
|
if (el.createTextRange) {
|
||||||
range = el.createTextRange();
|
range = el.createTextRange();
|
||||||
range.collapse(false);
|
range.collapse(false);
|
||||||
range.select();
|
range.select();
|
||||||
|
} else if (el.setSelectionRange) {
|
||||||
|
len = this.search.val().length;
|
||||||
|
el.setSelectionRange(len, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.focusser.prop("disabled", true).val("");
|
this.focusser.prop("disabled", true).val("");
|
||||||
@ -1780,7 +1789,11 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
container = this.container,
|
container = this.container,
|
||||||
dropdown = this.dropdown;
|
dropdown = this.dropdown;
|
||||||
|
|
||||||
this.showSearch(false);
|
if (this.opts.minimumResultsForSearch < 0) {
|
||||||
|
this.showSearch(false);
|
||||||
|
} else {
|
||||||
|
this.showSearch(true);
|
||||||
|
}
|
||||||
|
|
||||||
this.selection = selection = container.find(".select2-choice");
|
this.selection = selection = container.find(".select2-choice");
|
||||||
|
|
||||||
@ -1864,9 +1877,11 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
|
|
||||||
installKeyUpChangeEvent(this.focusser);
|
installKeyUpChangeEvent(this.focusser);
|
||||||
this.focusser.on("keyup-change input", this.bind(function(e) {
|
this.focusser.on("keyup-change input", this.bind(function(e) {
|
||||||
e.stopPropagation();
|
if (this.opts.minimumResultsForSearch >= 0) {
|
||||||
if (this.opened()) return;
|
e.stopPropagation();
|
||||||
this.open();
|
if (this.opened()) return;
|
||||||
|
this.open();
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
selection.on("mousedown", "abbr", this.bind(function (e) {
|
selection.on("mousedown", "abbr", this.bind(function (e) {
|
||||||
@ -2043,19 +2058,20 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
this.highlight(selected);
|
this.highlight(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the search box if this is the first we got the results and there are enough of them for search
|
// hide the search box if this is the first we got the results and there are enough of them for search
|
||||||
|
|
||||||
if (initial === true && this.showSearchInput === false) {
|
if (initial === true) {
|
||||||
var min=this.opts.minimumResultsForSearch;
|
var min = this.opts.minimumResultsForSearch;
|
||||||
if (min>=0) {
|
if (min >= 0) {
|
||||||
this.showSearch(countResults(data.results)>=min);
|
this.showSearch(countResults(data.results) >= min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// single
|
// single
|
||||||
showSearch: function(showSearchInput) {
|
showSearch: function(showSearchInput) {
|
||||||
|
if (this.showSearchInput === showSearchInput) return;
|
||||||
|
|
||||||
this.showSearchInput = showSearchInput;
|
this.showSearchInput = showSearchInput;
|
||||||
|
|
||||||
this.dropdown.find(".select2-search").toggleClass("select2-search-hidden", !showSearchInput);
|
this.dropdown.find(".select2-search").toggleClass("select2-search-hidden", !showSearchInput);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user