You need to sign in to do that
Don't have an account?
Greg Finzer
How to output raw HTML in Lightning?
I have a flat set of data that I need to turn into a pivot table in a lightning component.
Initially I tried this:
<aura:iteration var="element" items="{!v.elements}">
<!-- Begin Table Row -->
<aura:If isTrue="{!element.StartElement}">
<aura:unescapedHtml value="<tr>" />
</aura:If>
I am presented with this error:
Failed to save FRCElementMatrixComponent.cmp: c:FRCElementMatrixComponent:57,44: ParseError at [row,col]:[58,44] Message: The value of attribute "value" associated with an element type "aura:unescapedHtml" must not contain the '<' character.: Source
So I tried to set an attribute called beginTR and set the value in JavaScript:
<aura:If isTrue="{!element.StartElement}">
<aura:unescapedHtml value="{!v.beginTR}" />
</aura:If>
This does not work as it cleans out the <tr> before it is output.
Is there any way I can output straight HTML in lightning? If not is there any other way to it in Salesforce? Visual Force, React, etc.
Initially I tried this:
<aura:iteration var="element" items="{!v.elements}">
<!-- Begin Table Row -->
<aura:If isTrue="{!element.StartElement}">
<aura:unescapedHtml value="<tr>" />
</aura:If>
I am presented with this error:
Failed to save FRCElementMatrixComponent.cmp: c:FRCElementMatrixComponent:57,44: ParseError at [row,col]:[58,44] Message: The value of attribute "value" associated with an element type "aura:unescapedHtml" must not contain the '<' character.: Source
So I tried to set an attribute called beginTR and set the value in JavaScript:
<aura:If isTrue="{!element.StartElement}">
<aura:unescapedHtml value="{!v.beginTR}" />
</aura:If>
This does not work as it cleans out the <tr> before it is output.
Is there any way I can output straight HTML in lightning? If not is there any other way to it in Salesforce? Visual Force, React, etc.
Thanks for your help. At this point I have determined that it is not possible to do a pivot table with lightning since it strips out HTML that does not have an end tag.
So if I do this:
component.set("v.beginTR", "begin<TR>");
It will strip out the <TR> and it outputs: begin
If I do this:
component.set("v.beginTR", "<TR><TD>begin</TD></TR>");
It will not strip it since there are beginning and ending tags. I thought about rendering the entire table as well, the problem is that the cells need to be styled differently and there will be checkboxes that the user needs to click and I need to bind to events to update data.
So, I am going to create a bunch of divs that are inline-block. I guess I am not surprised, Lightning is only a year old. HTML and Classic ASP were very limited when it first came out too.
Thanks everyone.
Greg
All Answers
https://wedgecommerce.com/unescapedhtml-in-lightning-component/
Thanks for the quick response.
I tried that eariler as well. Salesforce does not allow the < or > inside of a default.
Greg
Raw html (impossible to save directly indeed)
Escaped String:
https://www.freeformatter.com/html-escape.html#ad-output
Thanks for your help. At this point I have determined that it is not possible to do a pivot table with lightning since it strips out HTML that does not have an end tag.
So if I do this:
component.set("v.beginTR", "begin<TR>");
It will strip out the <TR> and it outputs: begin
If I do this:
component.set("v.beginTR", "<TR><TD>begin</TD></TR>");
It will not strip it since there are beginning and ending tags. I thought about rendering the entire table as well, the problem is that the cells need to be styled differently and there will be checkboxes that the user needs to click and I need to bind to events to update data.
So, I am going to create a bunch of divs that are inline-block. I guess I am not surprised, Lightning is only a year old. HTML and Classic ASP were very limited when it first came out too.
Thanks everyone.
Greg