function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ashima nidhiAshima nidhi 

setCustomValidity and reportValidity at record level lightning component

I am adding and removing the row dynamically using list iteration.
 
<aura:iteration items="{!v.accList}" var="abc" indexVar="index">
<td>
 <lightning:input aura:id="abc-start-date" name="accName" type="date" required="true"  label="Date From" value="{!abc.Start_Date__c}" />
</td>
<td colspan="3">
<lightning:textarea aura:id="abc-comment"  name="accComment" label="Comment" value=" 
{!abc.Comments__c}" placeholder="Comments"/>
</td>
</aura:iteration>



at helper/controller
 
for (var i = 0; i < accList.length; i++) {
 conditioncheck
 component.find('abc-comment').setCustomValidity("Comments can't be blank.");
 component.find('abc-comment').reportValidity();
}

However, for multiple record it is failing as the abc-comment are multiple on the basis of list. Is there any way to put the validation message on the basis of record for which error/validation needs to be thrown
Danish HodaDanish Hoda
Hi Ashima,
You need to set aura:id unique for every iterating var, you can set it as:
aura:id="{!index + 'abc-start-date'}"