From 08098d90b920073d831dc984de898a6ddb109fe8 Mon Sep 17 00:00:00 2001
From: Stefan Giehl <stefan@piwik.org>
Date: Fri, 7 Jul 2017 12:15:39 +0200
Subject: [PATCH] prevent angular compiler from screwing up selected values
 (#11781)

---
 plugins/SegmentEditor/javascripts/Segmentation.js | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/plugins/SegmentEditor/javascripts/Segmentation.js b/plugins/SegmentEditor/javascripts/Segmentation.js
index 1ca8bfc014..0153a6b491 100644
--- a/plugins/SegmentEditor/javascripts/Segmentation.js
+++ b/plugins/SegmentEditor/javascripts/Segmentation.js
@@ -1012,7 +1012,6 @@ Segmentation = (function($) {
             }
             // remove any remaining forms
 
-
             self.form = getFormHtml();
             self.target.prepend(self.form);
 
@@ -1028,8 +1027,11 @@ Segmentation = (function($) {
 
             placeSegmentationFormControls();
 
+            // needs to be done before jQuery selects are built, as angular compiler screws up the selected values
+            piwikHelper.compileAngularComponents(self.target);
+
             if(mode == "edit") {
-                var userSelector = $(self.form).find('.enable_all_users_select > option[value="' + segment.enable_all_users + '"]').prop("selected",true);
+                $(self.form).find('.enable_all_users_select > option[value="' + segment.enable_all_users + '"]').prop("selected",true);
 
                 // Replace "Visible to me" by "Visible to $login" when user is super user
                 if(hasSuperUserAccessAndSegmentCreatedByAnotherUser(segment)) {
@@ -1056,8 +1058,6 @@ Segmentation = (function($) {
             $(".segmentListContainer", self.target).hide();
 
             self.target.closest('.segmentEditorPanel').addClass('editing');
-
-            piwikHelper.compileAngularComponents(self.target);
         };
 
         var closeForm = function () {
-- 
GitLab