Skip to content

Commit f63a10c

Browse files
committed
ready for single
1 parent fcea152 commit f63a10c

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

select2.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,23 @@ the specific language governing permissions and limitations under the Apache Lic
16601660
if ($.isFunction(callback))
16611661
callback({id: selected.attr("value"), text: selected.text(), element:selected});
16621662
};
1663+
} else if ("data" in opts) {
1664+
// install default initSelection when applied to hidden input and data is local
1665+
opts.initSelection = opts.initSelection || function (element, callback) {
1666+
var data,
1667+
id = element.val();
1668+
1669+
$.each(opts.data, function(k, v){
1670+
if(id == opts.id(v)) {
1671+
data = v;
1672+
return false;
1673+
}
1674+
});
1675+
1676+
if ($.isFunction(callback)) {
1677+
callback(data);
1678+
}
1679+
};
16631680
}
16641681

16651682
return opts;

0 commit comments

Comments
 (0)