question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sap.ui.core.HTML binding content issue

See original GitHub issue

OpenUI5 version: 1.52.5

Browser/version (+device/version): Chrome

Any other tested browsers/devices(OK/FAIL): No

URL (minimal example if possible): https://ui5issues-a854a7813.dispatcher.hana.ondemand.com/index.html?hc_reset#/objectpagelayout

Steps to reproduce the problem: If i am binding the html markup using

<core:HTML content="{ui>/html}" sanitizeContent="true"/>

after changing the value, the bound html will be appended instead of replaced.

You can reporduce this in my example by triggering the section action “setHTML” which does

this._oViewModel.setProperty("/html", this._sHTML + "<b>" + Date.now() + "</b>");

What is the expected result? html code will be replaced

What happens instead? html code will be appended. The same line will be shown multiple times (to recognize this, i added Date.now() to the output).

Regards Holger

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
codeworriorcommented, Feb 27, 2018

When you increase the log level so that UI5 also logs warnings, you’ll notice that the HTML control complains about the content that it receives:

[Unsupported Feature]: Element sap.ui.core.HTML#__html0 has rendered 5 root nodes!

If multiple root elements are given, the UI5 re-rendering doesn’t work. The HTML control only issues a warning in this case as in the past we had some use cases that didn’t require re-rendering.

Nevertheless, I wondered about the number of 5 root nodes. This seems to be caused by the content string:

<p><h2>This is my headline...</h2><br/>text</p>

According to the HTML5 spec, the content model for <p> is phrasing content, but <h2> is no phrasing content. Furthermore, the spec allows to omit the closing </p> when e.g. <h2> tag follows. So the browser parses the string automatically as

<p></p> <h2>This is my headline...</h2> <br> text <p></p>

which indeed gives 5 root nodes (one of them a text node).

When I change the wrapper to a <div> instead of <p>and pay attention that setHtml also creates the same (and does not append another root node <b>), then it works as expected.

0reactions
codeworriorcommented, Feb 28, 2018

That’s what I meant with my last comment:

Adding such a wrapper automatically would be worth another property in the HTML control, I guess.

For compatibility reasons, we can’t always add a wrapper.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Component - Binding issue - SAP Community
I am trying to bind the HTML component content attribute with data returned from an OData service. I made sure that the OData...
Read more >
Data binding for HTML in XMLView - SAP Community
Hi, Is there any way to bind data from a model to the native HTML tag in an XML view? Below is an...
Read more >
SAPUI5 sap.ui.core HTML rendering redirecting on binding ...
Dear Experts, I am using sap.ui.core.HTML link , I am binding custom HTML coming from the external service that I am saving in...
Read more >
Data Binding not working - SAP Community
We are trying to bind data from controller to view but for some reason We are unable to display data in the view....
Read more >
Does data binding works on html element <html:div>
I know we could do property, element, aggregation binding in SAPUI5. new sap . ui . commons . TextField ({ value: "{name}" })...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found