Why are my classes being removed when using popupTemplate?

557
2
Jump to solution
01-03-2020 08:33 AM
Highlighted
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.

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor III

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

2 Replies
Highlighted
Occasional Contributor III

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

Highlighted
New Contributor II

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

Reply
0 Kudos