Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
While binding the data to popover, the 2nd click onwards it shows the error - You cannot apply bindings multiple times to the same element. How do you fix it?

Apologies, here is a sample code.
<pre lang="HTML">


 <a   id="testlnk" "popover:'settingsPopover'">
Link Test
</a>
      
//Template For Pop Up  

<script type="text/html" id="settingsPopover">

    <table >
    <tbody data-bind="foreach:EmpList">
    <tr >    
    <td >   
 <div>   
<input type="radio" style="padding:0px !important;vertical-align:top"/>
  <span  class="labelPrimary" style="vertical-align:top;padding:0px !important" data-bind="text:name"  >
     
    </span>

      </div>
  </td>  
    </tr >
     </tbody>
     </table>
         <table >
     <tbody>
   <tr  >
    <td > 
       <div >
    <button id="btnOk" style="width: 100%"
                                >
                               OK
                            </button>
                            </div></td>
    </tr>
    </tbody>
    </table>
 </script>     


The Knockout Binding is as follows -
<pre lang="Javascript">
ko.bindingHandlers.popover = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
                var tmplId = ko.utils.unwrapObservable(valueAccessor());
                var tmplHtml = $('#' + tmplId).html();
               
                var domId = "Testing";
                var tmplDom = $('<div/>', {

                    "id": domId,
                    "data-bind": "withProperties: { EmpList: viewModel.EmployeeList  }"
                }).html(tmplHtml);


                var settingsup = {
                    trigger: 'manual',
                    closeable: true,                
                    title: " ",
                    dismissible: true
                };
                var contup = $("#settingsPopover").html();
                var applied = false;
               
                var conSetup = { content: tmplDom[0].outerHTML, width: 500, placement: 'auto', constrains: 'vertical', style: '' };

                $(element).webuiPopover($.extend({}, settingsup, conSetup));

                    $(element).bind('click', function () {
           
             

                $(element).webuiPopover('show');
            
                if ($('#' + domId).is(':visible')) {
                   
                    ko.applyBindings(viewModel, $('#' + domId)[0]);
                

               }
            }
        });

    }
};

ko.bindingHandlers.withProperties = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
        // Make a modified binding context, with a extra properties, and apply it to descendant elements
        var newProperties = valueAccessor(),
            innerBindingContext = bindingContext.extend(newProperties);
        ko.applyBindingsToDescendants(innerBindingContext, element);

        // Also tell KO *not* to bind the descendants itself, otherwise they will be bound twice
        return { controlsDescendantBindings: true };
    }
};



The issue is the employee list is updated based on some other event on the page.This new employee data is to be displayed on the pop up in a radio button list.

I'm using a pop-up plugin (https://github.com/sandywalker/webui-popover).
Posted
Updated 13-Jul-15 22:49pm
v3
Comments
Kornfeld Eliyahu Peter 13-Jul-15 9:16am    
Clean the previous binding before the new one?
It would be much easier to help you if you would be so nice to show us the relevant code...
Member 11833678 14-Jul-15 4:14am    
I have followed the same concept as mentioned in article here "http://www.codeproject.com/Tips/740940/Integrating-Knockout-with-Twitter-Bootstrap-Popove"
However second time I try to open the popup i get the error "you cannot apply bindings multiple times to the same element. "
Please suggest on possible solutions
F-ES Sitecore 14-Jul-15 4:22am    
You're just repeating the question that we can't answer as you haven't posted your code. Use "Improve question" to post the relevant code if you want people to help.
Member 11833678 14-Jul-15 6:04am    
Hi,
I have added sample code to support the question.
Please let me know if its unclear
Member 11833678 6-Aug-15 2:54am    
Hi,
I have added sample code to support the question.
Please let me know if its unclear

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900