Stop event propogation from DOM elements created dynamically via a library












1















I'm using AngularJS 1.7.5, x-editable, and smart table. Inside of a table row I have an anchor which opens a select via x-editable. I am also enabling row selection in smart table.



The problem is that I am unsure of how to stop the click event from the select from propogating and selecting or deselecting the table row. I have written a directive to suppress the click from the A element which opens the select, but the select is created by the x-editable library (e.g. not in my HTML.)



https://plnkr.co/edit/kAKbgLg05uBA9etICxV7?p=preview



<!DOCTYPE html>
<html ng-app="myApp">

<head>
<script data-require="jquery@*" data-semver="3.2.1" src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
<script data-require="angular.js@1.7.0" data-semver="1.7.0" src="https://code.angularjs.org/1.7.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-smart-table/2.1.8/smart-table.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap-tpls.js"></script>
<script data-require="xeditable@*" data-semver="0.1.8" src="https://vitalets.github.io/angular-xeditable/dist/js/xeditable.js"></script>
<link data-require="bootstrap-css@3.3.7" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>

<body ng-controller="myController as $ctrl">
<table st-table="collection" class="table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Secret Identity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in collection" st-select-row="row" st-select-mode="multiple">
<td>{{ row.id }}</td>
<td>{{ row.name }}</td>
<td>
<a href="#" editable-select="row.secretIdentity" data-value="{{ row.secretIdentity }}" class="editable editable-click" buttons="no" mode="inline" e-ng-options="i for i in options" stop-event="click">
{{ row.secretIdentity }}
</a>
</td>
</tr>
</tbody>
</table>
</body>

</html>




angular
.module('myApp', ['xeditable', 'smart-table', 'ui.bootstrap'])
.controller('myController', ['$scope', 'editableOptions', function($scope, editableOptions) {
editableOptions.theme = 'bs3';

$scope.collection = [{
name: 'Ed',
id: 1,
secretIdentity: 'Just some guy'
}, {
name: 'Tony',
id: 2,
secretIdentity: 'Iron Man'
}, {
name: 'Steve',
id: 3,
secretIdentity: 'Captain America'
}, {
name: 'Bruce',
id: 4,
secretIdentity: 'Hulk'
}, {
name: 'Clint',
id: 5,
secretIdentity: 'Hawkeye'
}, {
name: 'Natasha',
id: 6,
secretIdentity: 'Black Widow'
}, ];

$scope.options = ['Iron Man', 'Captain America', 'Hulk', 'Black Widow', 'Hawkeye', 'Just some guy'];
}])




  .directive('stopEvent', () => {
return {
restrict: 'A',
link: (scope, element, attr) => {
if (attr && attr.stopEvent) {
element.bind(attr.stopEvent, e => {
e.stopPropagation();
});
}
}
};
});


Is there a standard way for manipulating elements created by x-editable which will also play nice with AngularJS?










share|improve this question





























    1















    I'm using AngularJS 1.7.5, x-editable, and smart table. Inside of a table row I have an anchor which opens a select via x-editable. I am also enabling row selection in smart table.



    The problem is that I am unsure of how to stop the click event from the select from propogating and selecting or deselecting the table row. I have written a directive to suppress the click from the A element which opens the select, but the select is created by the x-editable library (e.g. not in my HTML.)



    https://plnkr.co/edit/kAKbgLg05uBA9etICxV7?p=preview



    <!DOCTYPE html>
    <html ng-app="myApp">

    <head>
    <script data-require="jquery@*" data-semver="3.2.1" src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
    <script data-require="angular.js@1.7.0" data-semver="1.7.0" src="https://code.angularjs.org/1.7.0/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-smart-table/2.1.8/smart-table.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap-tpls.js"></script>
    <script data-require="xeditable@*" data-semver="0.1.8" src="https://vitalets.github.io/angular-xeditable/dist/js/xeditable.js"></script>
    <link data-require="bootstrap-css@3.3.7" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
    </head>

    <body ng-controller="myController as $ctrl">
    <table st-table="collection" class="table">
    <thead>
    <tr>
    <th>Id</th>
    <th>Name</th>
    <th>Secret Identity</th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="row in collection" st-select-row="row" st-select-mode="multiple">
    <td>{{ row.id }}</td>
    <td>{{ row.name }}</td>
    <td>
    <a href="#" editable-select="row.secretIdentity" data-value="{{ row.secretIdentity }}" class="editable editable-click" buttons="no" mode="inline" e-ng-options="i for i in options" stop-event="click">
    {{ row.secretIdentity }}
    </a>
    </td>
    </tr>
    </tbody>
    </table>
    </body>

    </html>




    angular
    .module('myApp', ['xeditable', 'smart-table', 'ui.bootstrap'])
    .controller('myController', ['$scope', 'editableOptions', function($scope, editableOptions) {
    editableOptions.theme = 'bs3';

    $scope.collection = [{
    name: 'Ed',
    id: 1,
    secretIdentity: 'Just some guy'
    }, {
    name: 'Tony',
    id: 2,
    secretIdentity: 'Iron Man'
    }, {
    name: 'Steve',
    id: 3,
    secretIdentity: 'Captain America'
    }, {
    name: 'Bruce',
    id: 4,
    secretIdentity: 'Hulk'
    }, {
    name: 'Clint',
    id: 5,
    secretIdentity: 'Hawkeye'
    }, {
    name: 'Natasha',
    id: 6,
    secretIdentity: 'Black Widow'
    }, ];

    $scope.options = ['Iron Man', 'Captain America', 'Hulk', 'Black Widow', 'Hawkeye', 'Just some guy'];
    }])




      .directive('stopEvent', () => {
    return {
    restrict: 'A',
    link: (scope, element, attr) => {
    if (attr && attr.stopEvent) {
    element.bind(attr.stopEvent, e => {
    e.stopPropagation();
    });
    }
    }
    };
    });


    Is there a standard way for manipulating elements created by x-editable which will also play nice with AngularJS?










    share|improve this question



























      1












      1








      1








      I'm using AngularJS 1.7.5, x-editable, and smart table. Inside of a table row I have an anchor which opens a select via x-editable. I am also enabling row selection in smart table.



      The problem is that I am unsure of how to stop the click event from the select from propogating and selecting or deselecting the table row. I have written a directive to suppress the click from the A element which opens the select, but the select is created by the x-editable library (e.g. not in my HTML.)



      https://plnkr.co/edit/kAKbgLg05uBA9etICxV7?p=preview



      <!DOCTYPE html>
      <html ng-app="myApp">

      <head>
      <script data-require="jquery@*" data-semver="3.2.1" src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
      <script data-require="angular.js@1.7.0" data-semver="1.7.0" src="https://code.angularjs.org/1.7.0/angular.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-smart-table/2.1.8/smart-table.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap-tpls.js"></script>
      <script data-require="xeditable@*" data-semver="0.1.8" src="https://vitalets.github.io/angular-xeditable/dist/js/xeditable.js"></script>
      <link data-require="bootstrap-css@3.3.7" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
      <link rel="stylesheet" href="style.css" />
      <script src="script.js"></script>
      </head>

      <body ng-controller="myController as $ctrl">
      <table st-table="collection" class="table">
      <thead>
      <tr>
      <th>Id</th>
      <th>Name</th>
      <th>Secret Identity</th>
      </tr>
      </thead>
      <tbody>
      <tr ng-repeat="row in collection" st-select-row="row" st-select-mode="multiple">
      <td>{{ row.id }}</td>
      <td>{{ row.name }}</td>
      <td>
      <a href="#" editable-select="row.secretIdentity" data-value="{{ row.secretIdentity }}" class="editable editable-click" buttons="no" mode="inline" e-ng-options="i for i in options" stop-event="click">
      {{ row.secretIdentity }}
      </a>
      </td>
      </tr>
      </tbody>
      </table>
      </body>

      </html>




      angular
      .module('myApp', ['xeditable', 'smart-table', 'ui.bootstrap'])
      .controller('myController', ['$scope', 'editableOptions', function($scope, editableOptions) {
      editableOptions.theme = 'bs3';

      $scope.collection = [{
      name: 'Ed',
      id: 1,
      secretIdentity: 'Just some guy'
      }, {
      name: 'Tony',
      id: 2,
      secretIdentity: 'Iron Man'
      }, {
      name: 'Steve',
      id: 3,
      secretIdentity: 'Captain America'
      }, {
      name: 'Bruce',
      id: 4,
      secretIdentity: 'Hulk'
      }, {
      name: 'Clint',
      id: 5,
      secretIdentity: 'Hawkeye'
      }, {
      name: 'Natasha',
      id: 6,
      secretIdentity: 'Black Widow'
      }, ];

      $scope.options = ['Iron Man', 'Captain America', 'Hulk', 'Black Widow', 'Hawkeye', 'Just some guy'];
      }])




        .directive('stopEvent', () => {
      return {
      restrict: 'A',
      link: (scope, element, attr) => {
      if (attr && attr.stopEvent) {
      element.bind(attr.stopEvent, e => {
      e.stopPropagation();
      });
      }
      }
      };
      });


      Is there a standard way for manipulating elements created by x-editable which will also play nice with AngularJS?










      share|improve this question
















      I'm using AngularJS 1.7.5, x-editable, and smart table. Inside of a table row I have an anchor which opens a select via x-editable. I am also enabling row selection in smart table.



      The problem is that I am unsure of how to stop the click event from the select from propogating and selecting or deselecting the table row. I have written a directive to suppress the click from the A element which opens the select, but the select is created by the x-editable library (e.g. not in my HTML.)



      https://plnkr.co/edit/kAKbgLg05uBA9etICxV7?p=preview



      <!DOCTYPE html>
      <html ng-app="myApp">

      <head>
      <script data-require="jquery@*" data-semver="3.2.1" src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script>
      <script data-require="angular.js@1.7.0" data-semver="1.7.0" src="https://code.angularjs.org/1.7.0/angular.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-smart-table/2.1.8/smart-table.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/1.1.2/ui-bootstrap-tpls.js"></script>
      <script data-require="xeditable@*" data-semver="0.1.8" src="https://vitalets.github.io/angular-xeditable/dist/js/xeditable.js"></script>
      <link data-require="bootstrap-css@3.3.7" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
      <link rel="stylesheet" href="style.css" />
      <script src="script.js"></script>
      </head>

      <body ng-controller="myController as $ctrl">
      <table st-table="collection" class="table">
      <thead>
      <tr>
      <th>Id</th>
      <th>Name</th>
      <th>Secret Identity</th>
      </tr>
      </thead>
      <tbody>
      <tr ng-repeat="row in collection" st-select-row="row" st-select-mode="multiple">
      <td>{{ row.id }}</td>
      <td>{{ row.name }}</td>
      <td>
      <a href="#" editable-select="row.secretIdentity" data-value="{{ row.secretIdentity }}" class="editable editable-click" buttons="no" mode="inline" e-ng-options="i for i in options" stop-event="click">
      {{ row.secretIdentity }}
      </a>
      </td>
      </tr>
      </tbody>
      </table>
      </body>

      </html>




      angular
      .module('myApp', ['xeditable', 'smart-table', 'ui.bootstrap'])
      .controller('myController', ['$scope', 'editableOptions', function($scope, editableOptions) {
      editableOptions.theme = 'bs3';

      $scope.collection = [{
      name: 'Ed',
      id: 1,
      secretIdentity: 'Just some guy'
      }, {
      name: 'Tony',
      id: 2,
      secretIdentity: 'Iron Man'
      }, {
      name: 'Steve',
      id: 3,
      secretIdentity: 'Captain America'
      }, {
      name: 'Bruce',
      id: 4,
      secretIdentity: 'Hulk'
      }, {
      name: 'Clint',
      id: 5,
      secretIdentity: 'Hawkeye'
      }, {
      name: 'Natasha',
      id: 6,
      secretIdentity: 'Black Widow'
      }, ];

      $scope.options = ['Iron Man', 'Captain America', 'Hulk', 'Black Widow', 'Hawkeye', 'Just some guy'];
      }])




        .directive('stopEvent', () => {
      return {
      restrict: 'A',
      link: (scope, element, attr) => {
      if (attr && attr.stopEvent) {
      element.bind(attr.stopEvent, e => {
      e.stopPropagation();
      });
      }
      }
      };
      });


      Is there a standard way for manipulating elements created by x-editable which will also play nice with AngularJS?







      angularjs x-editable smart-table






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 11:27









      georgeawg

      33.3k105068




      33.3k105068










      asked Dec 31 '18 at 20:59









      Ed S.Ed S.

      102k18150222




      102k18150222
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can wrap your <a> in a <div> and add your stop-event directive to that div.



          <td>
          <div stop-event="click">
          <a href="#"
          editable-select="row.secretIdentity"
          data-value="{{ row.secretIdentity }}"
          class="editable editable-click"
          buttons="no"
          mode="inline"
          e-ng-options="i for i in options"
          >
          {{ row.secretIdentity }}
          </a>
          </div>
          </td>





          share|improve this answer


























          • That... Makes sense. If you weren't able to tell, I'm not a UI dev. Thanks, I'll try it out when I'm back in the office.

            – Ed S.
            Jan 1 at 1:03











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991373%2fstop-event-propogation-from-dom-elements-created-dynamically-via-a-library%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You can wrap your <a> in a <div> and add your stop-event directive to that div.



          <td>
          <div stop-event="click">
          <a href="#"
          editable-select="row.secretIdentity"
          data-value="{{ row.secretIdentity }}"
          class="editable editable-click"
          buttons="no"
          mode="inline"
          e-ng-options="i for i in options"
          >
          {{ row.secretIdentity }}
          </a>
          </div>
          </td>





          share|improve this answer


























          • That... Makes sense. If you weren't able to tell, I'm not a UI dev. Thanks, I'll try it out when I'm back in the office.

            – Ed S.
            Jan 1 at 1:03
















          1














          You can wrap your <a> in a <div> and add your stop-event directive to that div.



          <td>
          <div stop-event="click">
          <a href="#"
          editable-select="row.secretIdentity"
          data-value="{{ row.secretIdentity }}"
          class="editable editable-click"
          buttons="no"
          mode="inline"
          e-ng-options="i for i in options"
          >
          {{ row.secretIdentity }}
          </a>
          </div>
          </td>





          share|improve this answer


























          • That... Makes sense. If you weren't able to tell, I'm not a UI dev. Thanks, I'll try it out when I'm back in the office.

            – Ed S.
            Jan 1 at 1:03














          1












          1








          1







          You can wrap your <a> in a <div> and add your stop-event directive to that div.



          <td>
          <div stop-event="click">
          <a href="#"
          editable-select="row.secretIdentity"
          data-value="{{ row.secretIdentity }}"
          class="editable editable-click"
          buttons="no"
          mode="inline"
          e-ng-options="i for i in options"
          >
          {{ row.secretIdentity }}
          </a>
          </div>
          </td>





          share|improve this answer















          You can wrap your <a> in a <div> and add your stop-event directive to that div.



          <td>
          <div stop-event="click">
          <a href="#"
          editable-select="row.secretIdentity"
          data-value="{{ row.secretIdentity }}"
          class="editable editable-click"
          buttons="no"
          mode="inline"
          e-ng-options="i for i in options"
          >
          {{ row.secretIdentity }}
          </a>
          </div>
          </td>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 31 '18 at 21:58

























          answered Dec 31 '18 at 21:45









          Dhruv PrakashDhruv Prakash

          1521210




          1521210













          • That... Makes sense. If you weren't able to tell, I'm not a UI dev. Thanks, I'll try it out when I'm back in the office.

            – Ed S.
            Jan 1 at 1:03



















          • That... Makes sense. If you weren't able to tell, I'm not a UI dev. Thanks, I'll try it out when I'm back in the office.

            – Ed S.
            Jan 1 at 1:03

















          That... Makes sense. If you weren't able to tell, I'm not a UI dev. Thanks, I'll try it out when I'm back in the office.

          – Ed S.
          Jan 1 at 1:03





          That... Makes sense. If you weren't able to tell, I'm not a UI dev. Thanks, I'll try it out when I'm back in the office.

          – Ed S.
          Jan 1 at 1:03




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991373%2fstop-event-propogation-from-dom-elements-created-dynamically-via-a-library%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas