Override method AttachBody._positionDropdown

375 views
Skip to first unread message

elvis....@exictos.com

unread,
Jun 15, 2016, 12:14:07 PM6/15/16
to select2
Hi, is it possible to override the method _positionDropdown, on AttachMethod class?

If yes, could an example be provided:
Currenly this is what I have, but after calling the constructor it will be missing an argument.

$.fn.select2.amd.define(
'select2/dropdown/customAttachBody',
[
'select2/dropdown/attachBody',
'select2/utils'
],
function (AttachBody, Utils) {

function customAttachBody() {
console.log(arguments);
customAttachBody.__super__.constructor.apply(this, arguments);
}

Utils.Extend(customAttachBody, AttachBody);

customAttachBody.prototype._positionDropdown = function () {
debugger;
}

return Utils.Decorate(customAttachBody, AttachBody);
}
);


var customAdapter = $.fn.select2.amd.require('select2/dropdown/customAttachBody');
/**/
$('select').select2({
dropdownAdapter: customAdapter
});
/**/

p.e.fl...@gmail.com

unread,
Oct 14, 2016, 10:11:28 AM10/14/16
to select2, elvis....@exictos.com

Did you happen to get this figured out?

elvis....@exictos.com

unread,
Oct 14, 2016, 10:18:06 AM10/14/16
to select2, elvis....@exictos.com, p.e.fl...@gmail.com

$.fn.select2.amd.require(
[
'select2/dropdown/attachBody'
],
function (AttachBody) {

// simple override
AttachBody.prototype._positionDropdown = function () {
// override code here
};

// or if you want to keep access to the original method
AttachBody.prototype._positionDropdown = (function (originalMethod) {

return function () {
// override code here
}

}(AttachBody.prototype._positionDropdown));

},
undefined,
true
);

Works fine like this.
Remember to execute the file where this code is set after the select2.js file.
Che

p.e.fl...@gmail.com

unread,
Oct 14, 2016, 10:24:47 AM10/14/16
to select2, elvis....@exictos.com, p.e.fl...@gmail.com

You're a champ! Thank you sir!

p.e.fl...@gmail.com

unread,
Oct 14, 2016, 11:51:34 AM10/14/16
to select2, elvis....@exictos.com, p.e.fl...@gmail.com

This works great, but I would still be interested in how to utilize this as a dropdownAdapter. I am going to cross post on stackoverflow.com

Reply all
Reply to author
Forward
0 new messages