Search code examples
javascriptjqueryknockout-3.0

javascript popup doesn't pop because bindings already assigned


The c# '/Clients/ClientSelectDataTable' gets called and returns.

      self.LookupClient = function () {
          $.ajax({
              type: 'POST',
              url: '/Clients/ClientSelectDataTable'
          }).done(function (msg) {
              //grab the partial from the controller
              $("#SelectClient").html('');
              $("#SelectClient").html(msg);
              //initialize the js
              theClientPicker = new ClientSelectModel('ClientSelectDataTable', '/API/GetAllClients', AssignClient, self.CancelClientSelect, "Select");
              ko.applyBindings(theClientPicker, $("#SelectClient")[0]);

              $.fancybox("#SelectClient", { //launch ClientSelect widget
                  modal: true,
                  afterClose: function () {
                      theClientPicker.Dispose();
                      ko.cleanNode($("#SelectClient")[0]);
                  }
              });
          });
      }

It throws an exception here ko.applyBindings(theClientPicker, $("#SelectClient")[0]);

...

    if (!sourceBindings) {
        if (alreadyBound) {
            throw Error("You cannot apply bindings multiple times to the same element.");

I can catch the exception, but the pop-up doesn't work because the events on the buttons are not assigned.

It is a new theClientPicker so I can't see how it can already be assigned.


Solution

  • Found the issue.
    This is either a bug or a breaking change in knockout, introduced between 3.4.2 and 3.5.0.
    Reverting back to, and freezing on, 3.4.2 fixes it.

    Is there a proper way to report this?