+ Start a Discussion
Nic EdwardsNic Edwards 

HTML5 Data Attributes on Lightning Components


In VisualForce you can specify a HTML5 data attribute by adding a html tag to the front - e.g.
<apex:input html-data-attribute-name="some data"/>

We are looking at trying a lightning implementation, but similar functionality is cruitial if we are to proceed.  Is there a way to append a HTML5 data attribute to a lightning component - e.g.
<ui:inputText data-attribute-name="some data"/>

Andy BoettcherAndy Boettcher
There are examples of the HTML5 data attributes all over the Lightning developer documentation - I'd say YUP!

Nic EdwardsNic Edwards
Hey, thanks for that.  So, which of the 317 pages describes this.  I've tried searching for data, attribute, and completing all the trailheads so I must have just missed it.

Andy BoettcherAndy Boettcher
You have to read between the lines a bit - look at the bottom of page 152 and 216 and you'll see them using the HTML5 data attributes themselves.
Here is an example using pass through variable in lightning components. ....

<aura:iteration items="{!v.SearchResults}" var="sr"  indexvar="index">
              <tr onclick="{!c.selected}" data-record="{!sr.Id}">   
               <td><ui:outputText value="{!sr.Id}"/></td>   


selected: function(cmp,event,helper){
          var selectedItem = event.currentTarget;
          var recId = selectedItem.dataset.record;
Vitalii Kaigorodtsev 7Vitalii Kaigorodtsev 7
ajithM, your answer is helpfull over the years! Thanks!
Miroslav MatovićMiroslav Matović
@ajithM that is setting a dataset attribute on a HTML element, not a component, like ui:inputText. If you try to add a dataset attribute on those, you get errors like: The attribute "data-id" was not found on the COMPONENT markup