Disable dropdown opening on select2 clear

You don’t require a timeout to make this work, here’s my example: $(‘#my-select’).select2({ allowClear: true }).on(‘select2:unselecting’, function() { $(this).data(‘unselecting’, true); }).on(‘select2:opening’, function(e) { if ($(this).data(‘unselecting’)) { $(this).removeData(‘unselecting’); e.preventDefault(); } });

Select2 – make it readonly (not disabled!) from js

This is Solution for Latest select2 (Tested With 4.0.7) using css only /*Select2 ReadOnly Start*/ select[readonly].select2-hidden-accessible + .select2-container { pointer-events: none; touch-action: none; } select[readonly].select2-hidden-accessible + .select2-container .select2-selection { background: #eee; box-shadow: none; } select[readonly].select2-hidden-accessible + .select2-container .select2-selection__arrow, select[readonly].select2-hidden-accessible + .select2-container .select2-selection__clear { display: none; } /*Select2 ReadOnly End*/

select2: cannot read property ‘id’ of undefined

If you set the debug property to true you’ll see a warning message. The allowClear option should be used in combination with the placeholder option. <!DOCTYPE html> <html> <head> <title></title> <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <link href=”https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css” rel=”stylesheet” /> <script src=”https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js”></script> </head> <body> <select role=”select” id=”myoption”> <option value=”001″>abcs </option><option value=”002″>dshdsh</option><option value=”003″>A</option> <option value=”004″>ANAM CO</option> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)