Sai Sathish
Sai Sathish

Reputation: 79

Angular UI Bootstrap Accordion Content Checkbox Not Working

I am using angularjs version 1.3.13 ,ui-bootstrap-tpls version 0.12 and angularjs ui router version 0.2.13. I want to show the template content inside the accordion by using ui-sref.After the template inside an accordion is loaded ,the click event does not trigger for checkbox component. Found events are prevented in below location for all elements except button For this issue i had added a condition in onclick bind event of ui-sref directive in angular-ui-router.js. Any one please tell me if this solution is correct or not?
My code is shown below.

<accordion>
  <accordion-group is-open="true" ui-sref="addContract.add">
    <accordion-heading>
      Settings <i class="pull-right glyphicon" 
                  ng-class="{'glyphicon-chevron-down': $state.includes('true'), 'glyphicon-chevron-down': !status.open}"></i>
    </accordion-heading>
  <div ui-view="kpiParamSettings" autoscroll="true"></div>
</accordion-group></accordion>

An ui-sref has the following html

<div>
  <label><input id="login-remember" name="remember" type="checkbox" value="1">Stop</label>
</div>
element.bind("click", function(e) {
        var button = e.which || e.button;
        if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) {
          // HACK: This is to allow ng-clicks to be processed before the transition is initiated:
          var transition = $timeout(function() {
            $state.go(ref.state, params, options);
          });
          e.preventDefault();

          // if the state has no URL, ignore one preventDefault from the <a> directive.
          var ignorePreventDefaultCount = isAnchor && !newHref ? 1: 0;
          e.preventDefault = function() {
            if (ignorePreventDefaultCount-- <= 0)
              $timeout.cancel(transition);
          };
        }
      });

In the above click event i added the following condition

    element.bind("click", function(e) {
if(e.target.type!="checkbox") // Condition for avoiding to bind the checkbox click event
      {
            var button = e.which || e.button;
            if ( !(button > 1 || e.ctrlKey || e.metaKey || e.shiftKey || element.attr('target')) ) {
              // HACK: This is to allow ng-clicks to be processed before the transition is initiated:
              var transition = $timeout(function() {
                $state.go(ref.state, params, options);
              });
              e.preventDefault();

              // if the state has no URL, ignore one preventDefault from the <a> directive.
              var ignorePreventDefaultCount = isAnchor && !newHref ? 1: 0;
              e.preventDefault = function() {
                if (ignorePreventDefaultCount-- <= 0)
                  $timeout.cancel(transition);
              };
            }
}
          });

Upvotes: 1

Views: 1354

Answers (2)

Sai Sathish
Sai Sathish

Reputation: 79

I had fixed an above issue by using the following accordion declaration.

My code is

<accordion>
   <accordion-group is-open="true" ui-sref="addContract.add"> 
     <accordion-heading>
    Settings <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': $state.includes('true'), 'glyphicon-chevron-down': !status.open}"></i>
     </accordion-heading>
      <div ui-view="kpiParamSettings" autoscroll="true"></div>
   </accordion-group>   
</accordion>

After edit the code ,the issue was fixed

<accordion>
   <accordion-group is-open="true"> // Removed ui-sref from this line
     <accordion-heading>
        <a ui-sref="addContract.add"> // Added a with ui-sref
            Settings <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': $state.includes('true'), 'glyphicon-chevron-down': !status.open}"></i>
        </a>
     </accordion-heading>
      <div ui-view="kpiParamSettings" autoscroll="true"></div>
   </accordion-group>   
</accordion>

Upvotes: 0

GMStevens
GMStevens

Reputation: 179

Using element.bind doesnt trigger a digest cycle, so your UI isnt getting updated. Either use ngClick or add $scope.$apply() to your click handler to manually trigger the digest cycle.

Upvotes: 1

Related Questions