My aim is to have a radio checkbox field, my current below implementation worked properly when locker service was disabled. But when locker service is enabled this is not working. Please help me.
<aura:component >
<ltng:require styles="/resource/slds0122/assets/styles/salesforce-lightning-design-system.min.css" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="exampleList" type="String[]"/>
<aura:attribute name="previousIndex" type="Integer" default="-1"/>
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<tbody>
<aura:iteration items="{!v.exampleList}" var="item">
<tr class="slds-hint-parent">
<td>
<ui:inputRadio change="{!c.radioSelect}" class="radio" />
</td>
<th>
{!item}
</th>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
Controller:
({
doInit : function(component) {
var items = [];
for(var i=0;i<7;i++){
var item = "Item_"+i;
items.push(item);
}
component.set("v.exampleList",items);
},
radioSelect : function(component) {
var index = component.get("v.previousIndex");
var elements = document.getElementsByClassName("radio");
if (index != "-1") {
elements[index].checked = false;
}
for ( var i = 0; i < elements.length; i++) {
if (elements[i].checked)
index = i;
}
component.set("v.previousIndex", index);
}
})
When locker service is enabled, document.getElementsByClassName is returning null and the elements length is 0. How to implement this with Locker service enabled. Thank you.