spModal.open({message: doesn't accept HTML tags?

JeremiP
Tera Guru

Hi everyone,

I'm trying to make a simple widget that would display a modal window, with contents taken from a dot walked HTML type field.

But it seems that the HTML tags get stripped away when it gets passed to the message key in spModal.open()'s first parameter Object.
Logging $scope.data shows that the HTML tags get captured properly by the Server Script in the Widget below...

find_real_file.png

HTML:

<div>
 <button type="button" class="btn btn-primary btn-block"
         ng-click="c.htmlModal()"> HTML box  </button>
</div>

Client Script:

function(spModal) {
  var c = this; c.htmlModal = function() {
		spModal.open({
			message: c.data.got,
			buttons: []
		})
	}
}

Server Script:

(function() {
	data.record = $sp.getRecord();
	var lookup = new GlideRecord(data.record.sys_class_name);
	lookup.get(data.record.getUniqueValue());
	data.got = lookup.html_field.toString();
})();

...
But the modal window displays the text without the formatting applied:

find_real_file.png

and Inspecting the element shows that the HTML tags are now stripped:

find_real_file.png

2 REPLIES 2

Willem
Giga Sage
Giga Sage

It is inserted using "ng-bind-html" by default that will sanitize the HTML:

Evaluates the expression and inserts the resulting HTML into the element in a secure way. By default, the resulting HTML content will be sanitized using the $sanitize service.

https://docs.angularjs.org/api/ng/directive/ngBindHtml

 

What that means is it will remove a lot, but leaves the tags in place as you see in your screenshots as well.

@JeremiP do you need any additional help? If not, kindly mark answer as Helpful and Correct to close the thread.