Why are my classes being removed when using popupTemplate?

3964
3
Jump to solution
01-03-2020 08:33 AM
JackFairfield
Occasional Contributor II

In the latest version of the js api (4.14), when I create a simple popup template like this:

...

popupTemplate:{
   title: 'test',
   content: '<div class="customClass">Green</div>'
}

...

Why is my "customClass" being removed in the resulting popup html?

Here is a simple example in JS Bin:     JS Bin - Collaborative JavaScript Debugging 

In this example, I would have expected the "Green" text in the body of the popup to appear green.

This issue doesn't seem to happen when reverting back to the 4.13 version of the api.

0 Kudos
1 Solution

Accepted Solutions
MattDriscoll
Esri Contributor

Hello,

In 4.14, we are using a HTML sanitizer (https://github.com/Esri/arcgis-html-sanitizer) which removes some HTML for security purposes. We may be able to do something for this in 4.15.

As an alternative workaround to a HTML string, you can do the following to modify a dom node directly.

var template = {
  content: function(){
    var div = document.createElement("div");
    div.className = "myClass";
    div.innerHTML = "<span>My custom content!</span>";
    return div;
  }
};

View solution in original post

3 Replies
MattDriscoll
Esri Contributor

Hello,

In 4.14, we are using a HTML sanitizer (https://github.com/Esri/arcgis-html-sanitizer) which removes some HTML for security purposes. We may be able to do something for this in 4.15.

As an alternative workaround to a HTML string, you can do the following to modify a dom node directly.

var template = {
  content: function(){
    var div = document.createElement("div");
    div.className = "myClass";
    div.innerHTML = "<span>My custom content!</span>";
    return div;
  }
};
PieterHoltzhausen1
New Contributor II

Matt. Please would you include this fix in 4.15. Much appreciated

0 Kudos
PieterHoltzhausen1
New Contributor II

Have this been fix in 4.18 ?

0 Kudos