I have a component which will display a list of records in the table format, and here I have a pick-list input field named Distance . Now on entering value in distance field and saving the record, record gets saved but the distance value is not getting populated in the record. If there is only one record, on entering distance value it will get saved and be populated. But when it handles more than one record, since aura:id inside aura:iteration is static , it throws an error component.get() is not a function.Since aura:id does not support dynamic id’s, I couldn’t get this done.
Component:
<aura:attribute name="diss" type="String"/>
<aura:attribute name="distanceval" type="String"/>//This value is fetched from Server side Controller.
<aura:if isTrue="{!v.LocationFound}">
<aura:iteration items="{!v.Location}" var="location" >
<tr>
<th>
<label class="slds-checkbox">
<ui:inputCheckbox aura:id="checkLocation" value="" text="{!location.Id}"/>
<span class="slds-checkbox--faux" />
<span class="slds-form-element__label"></span>
</label>
</th>
<th scope="row">
<div class="slds-truncate" title="Location Name">{!location.Name}</div>
</th>
<div class="slds-truncate" title="Distance" >
<lightning:select name="selectItem" label="Distance to TrainingLocation" value="" aura:id="dis" >
<option value=" " > --Select-- </option>
<aura:iteration items="{!v.distancevalue}" var="dist">
<option value="{!dist.value}"> {!dist.label} </option>
</aura:iteration>
</lightning:select>
</div>
Helper.js:
var distanceval=component.find('dis').get('v.value');
console.log('the distance values is>>>>>'+distanceval);
component.set("v.diss",distanceval);
console.log('value is>>>>>'+component.get('v.diss'));