Skip to content

Commit ebc436c

Browse files
committed
improve val() handling on multiselect. fixes select2#654
1 parent 2f53c25 commit ebc436c

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

select2.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,15 +1932,14 @@ the specific language governing permissions and limitations under the Apache Lic
19321932

19331933
if (opts.element.get(0).tagName.toLowerCase() === "select") {
19341934
// install sthe selection initializer
1935-
opts.initSelection = function (element,callback) {
1935+
opts.initSelection = function (element, callback) {
19361936

19371937
var data = [];
1938+
19381939
element.find(":selected").each2(function (i, elm) {
1939-
data.push({id: elm.attr("value"), text: elm.text(), element: elm});
1940+
data.push({id: elm.attr("value"), text: elm.text(), element: elm[0]});
19401941
});
1941-
1942-
if ($.isFunction(callback))
1943-
callback(data);
1942+
callback(data);
19441943
};
19451944
} else if ("data" in opts) {
19461945
// install default initSelection when applied to hidden input and data is local
@@ -2410,10 +2409,7 @@ the specific language governing permissions and limitations under the Apache Lic
24102409
this.setVal(val);
24112410

24122411
if (this.select) {
2413-
this.select.find(":selected").each(function () {
2414-
data.push({id: $(this).attr("value"), text: $(this).text()});
2415-
});
2416-
this.updateSelection(data);
2412+
this.opts.initSelection(this.select, this.bind(this.updateSelection));
24172413
if (triggerChange) {
24182414
this.triggerChange();
24192415
}

0 commit comments

Comments
 (0)