2 Replies Latest reply on Nov 8, 2013 7:20 AM by Karl Mayer

    Temporarily disabling Tableau JavaScript's MARKS_SELECTION event listener

    Karl Mayer

      I'm working on a JavaScript framework that integrates Tableau worksheets using Tableau's JavaScript API such that a selection in one sheet is applied to all others.  The sheets are dynamic thus this is my preferred solution.

       

      I need to disable the marks event listener so that my marks automation doesn't cause it to infinitely trigger.  It appears to me this should be done in the then() promise (shown below in bold) but unfortunately, the marks event is still triggered infinitely.  Help!

       

      As expected, removing addEventListener() in the then() promise stops the event from infinitely triggering -- but, of course, it only works once then.

       

      Here is the paired down code... it may not be perfect since I removed some extra code, but it demonstrates the pattern I'm attempting:

       

      Analytic.prototype.applyMarks = function (marks) {

          // remove marks selection listener to prevent selectMarksAsync from triggering it

          this.viz.removeEventListener(tableauSoftware.TableauEventName.MARKS_SELECTION, this.marksSelectionFunc);

           // set marks programmatically

          worksheet.selectMarksAsync(marks, tableauSoftware.SelectionUpdateType.REPLACE).then(

           // re-establish marks selection listener

                    $.proxy(this.viz.addEventListener(tableauSoftware.TableauEventName.MARKS_SELECTION, this.marksSelectionFunc), this);

              );

          }

      };