Problem:
The select2 jQuery plugin does not work when used in a jQuery dialog box nested in an element that uses with binding bindings. Remove the with binding, and select2 works fine. If with tied to a nested property, then it stops working.
Background:
So, I must have fought for 3 hours, trying to get select2 to work in the jQuery dialog .... talking about pi $$ inging over the notorious wrong tree, I thought it was purely jQuery dialog and choice2. It probably worked right from the start with the _allowInteraction fix. Until I broke the problem down to simple steps, and the reason began to unfold. The problem is with the with binding.
Renouncement
I apologize for working on asinine, which blocks jsFiddle. I also broke up my implementation for illustrative purposes, since the actual model is quite large.
<link href="http://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet"/> <link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.min.js"></script> <button data-bind="click: showTeam">Add Team</button> <div id="addTeamDialog"> <fieldset data-bind="with: department"> <div class="lite-dialog-field"> <div class="label"> <span data-bind="text: name"></span> </div> <div class="field"> <input type="hidden" id="someList" /> </div> </div> </fieldset> </div>
Removing data-bind in fieldset and select2 works fine.
When the data-bind parameter on fieldset set to department , select2 works fine.
If the data-bind parameter on fieldset set to department.selectedTeam , select2 does not work.
source share