I have similar requirement to this How to call child component controller function/helper from Parent Component Controller the parent component has a button that will call a function from child component. For more specific, I have function that should show error messages on the individual fields while in the <aura:iteration>
upon click of Save button.
ParentComponent.cmp
<aura:component>
<aura:iteration items="{!v.listRec}" var="individualRec">
<c:ChildComponent individualRec="{!individualRec}" aura:id="cComp"/>
</aura:iteration>
<button type="button" onclick="{!c.save}">Save</button>
</aura:component>
ParentController.js
({
save: function(component, event, helper) {
var childCmp = component.find("cComp");
childCmp.sampleMethod();
}
})
ChildComponent.cmp
<aura:component>
<aura:method name="sampleMethod" action="{!c.childSave}" access="PUBLIC" />
<aura:attribute name="individualRec" type="List" />
<label>Email</label>
<ui:inputText aura:id="inputEmail" value="{!v.individualRec.Email}" /
</aura:component>
ChildController.js
({
childSave : function(component, event, helper) {
var inputEmail = component.find("inputEmail");
var varEmail = inputEmail.get("v.value");
if ($A.util.isEmpty(varEmail)) {
inputEmail.set("v.errors", [{message:"Complete this field"}]);
}
}
})