+ Start a Discussion
vikas rathi91vikas rathi91 

validate child component from parent componet

We have created a lightning component. Inisde the component we are refering another component. we would like to validate the data inside child component on a button click from parent component.

Can anyone give some sample code or suggestion?

Thanks and RegardsUser-added image
Here we call child component

<div class="slds-modal__content slds-p-around--medium wide400">
                <!--Transaction Editor Component Here -->
                <!--<c:TransactionViewer thistrans="{!v.thistrans}" currencies="{!v.currencies}" 
                           tdetails="{!v.thisdetails}" /> -->

below is component  code is long so I paset only 2 field code

<div class="slds-form-element slds-size--1-of-3">
                            <!--<label class="slds-form-element__label" for="descrField">Description</label>-->
                            <!--<force:inputField aura:id="descrField" class="slds-textarea" value="{!v.thistrans.Description__c}"/> -->
                            <ui:inputText aura:id="descrField" class="slds-input" required="true" label="Description" value="{!v.thistrans.Description__c}"/>
                        <div class="slds-form-element slds-size--1-of-3">                            
                            <c:LookupSObject label="Deal/Tranche" pluralLabel="Deal/Tranches" sObjectAPIName="Tranche__c" instanceId="tnxTr"                          

And here is controller code
okTranerror: function(component){
        var tratitle = component.find("trannameField").get("v.value");
        var haserrors = false;
            effnamefld.set("v.errors", [{message:"Provide Name First!"}]);
            haserrors = true;
please help i m try a lot but not success

thanks in advance 
Ganesh Babu 8Ganesh Babu 8
Hello Accky,

You can use events to alert the parent component on validation. You can use events for all actions in child component.

eg: onclick, onhover.. etc.

Thanks and Regards,
Ganesh Babu.
vikas rathi91vikas rathi91
Hello Ganesh,

Thanks for reply. I am done the validation without the event actions. now I am not able to show error on the field that will be indicate that the value is null. I am using events on that to show the error but not success. 
pls help

below is code for component, client side controller, and helper to show the error where is problem i m not find 
<ui:inputText aura:id="trannameField" class="slds-input" required="true" label="Transaction Title" value="{!v.thistrans.Name}" mouseout="{!c.handleClick}" />

 handleClick : function(component, event, helper) {   

	handleClick : function(component) {
        var traname = component.find("trannameField").get("v.value");
        var haserrors = false;
            traname.set("v.errors", [{message:"Provide Name First!"}]);
            haserrors = true;
        if(haserrors) return;

Ganesh, did you ever find a solution?  If so, could you please share?   Thanks!!