[SalesForce] How to display second form by clicking first lightning component form

Here I'm displaying two forms in single page 1.customer login form and 2.customer details form.

By using phonenumber I can able to get data from salesforce by clicking a button and diplaing in customer details form.

Requirement is :

I don't want to display two forms in same page.How can I display login form first after clicking a button it display customer details form.

enter image description here

Component :

<aura:component controller="RPAProcess" implements="force:lightningQuickAction,flexipage:availableForAllPageTypes" access="global">
aura:attribute name="RPABot" type="RPABot__c" default="{'sobjectType':'RPABot__c'}" />
  aura:attribute name="PhoneNumber" type="String" default="" />

   div class="slds-page-header">
        div class="slds-align_absolute-center">
            div class="slds-text-heading_large">
                div class="slds-m-top_xx-large">
                    <b>  Customer Login Form </b>
                /div>
            /div>
        /div>
   /div>  
   div class="slds-size_3-of-12"> 
        lightning:input label="Phone Number" name="phonenumber" value="{!v.PhoneNumber}" required = "true"/>
        br/>  
        lightning:button variant="brand" label="Get Data" onclick="{!c.getData}" />       
  </div>  


    div class="slds-m-top_xx-large">
           <b>Cutomer Details </b>
    /div>

    div class="slds-size_3-of-12">
        lightning:input label="CustomerID" name="rpaId" value="{!v.RPABot.Customer_ID__c}" /> 
       <br/>    
        lightning:input label="Customer Name" name="customername" value="{!v.RPABot.Customer_Name__c}" />
        <br/>      
        lightning:input label="Company" name="dob" value="{!v.RPABot.Company__c}" />
        <br/>       >
    </div> 
/aura:component>

component.js

({
    getData : function(component, event, helper) {
        var action = component.get("c.getDetails");  

            action.setParams({  
            phonenumber : component.get("v.PhoneNumber")               
        });                  
          action.setCallback(this, function(response){                              
          component.set("v.RPABot",response.getReturnValue());      
        });
        $A.enqueueAction(action);
    },
})

Best Answer

  1. Add Customer_Name__c in default of attribute RPABot.

  2. Put 1st form and 2nd form in aura:if, such that 1st form is shown when Customer_Name__c is empty. When you get back the data Customer_Name__c is not empty and so 1st form is removed and 2nd form is rendered.

Below is the code of .cmp:

<aura:component controller="RPAProcess" implements="force:lightningQuickAction,flexipage:availableForAllPageTypes"
                access="global">

    <aura:attribute name="RPABot" type="RPABot__c" default="{'sobjectType':'RPABot__c','Customer_Name__c':''}" />
    <aura:attribute name="PhoneNumber" type="String" default="" />


    <aura:if isTrue="{!empty(v.RPABot.Customer_Name__c)}">
        <div class="slds-page-header">
            <div class="slds-align_absolute-center">
                <div class="slds-text-heading_large">
                    <div class="slds-m-top_xx-large">
                        <b> Customer Login Form </b>
                    </div>
                </div>
            </div>
        </div>
        <div class="slds-size_3-of-12">
            <lightning:input label="Phone Number" name="phonenumber" value="{!v.PhoneNumber}" required="true" />
            <br />
            <lightning:button variant="brand" label="Get Data" onclick="{!c.getData}" />
        </div>
    </aura:if>


    <aura:if isTrue="{!not(empty(v.RPABot.Customer_Name__c))}">
        <div class="slds-m-top_xx-large">
            <b>Cutomer Details </b>
        </div>
        <div class="slds-size_3-of-12">
            <lightning:input label="CustomerID" name="rpaId" value="{!v.RPABot.Customer_ID__c}" />
            <br />
            <lightning:input label="Customer Name" name="customername" value="{!v.RPABot.Customer_Name__c}" />
            <br />
            <lightning:input label="Company" name="dob" value="{!v.RPABot.Company__c}" />
            <br />
        </div>
    </aura:if>

</aura:component>
Related Topic