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
pinky1pinky1 

Lightning Components : Input Data Using Forms. Show/ Hide field based on condition.

Hi,

I have requirement to create a lightning component to show custom object (Computer__c) field on the form. Computer object has lookup relationship to Account object. So, when a user is creating a computer record when selected Account related field Industry has a value of "Energy" then only show Price__c field from the Computer__c object on the page if not hide the Price__c field from the Page.

I trie to create the Lightning Component but not sure how to display fields based on the Condition. The code is as follow's

Component:
<aura:component implements="forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global" >
            <aura:attribute name="fields" type="String[]" default="['Name','Carrier_Account__c','Brand__c']" />
            <aura:attribute name="recordId" type="String"/>
            <lightning:notificationsLibrary aura:id="notifLib"/>
  <lightning:recordForm objectApiName="Computer__c" fields="{!v.fields}" onsuccess="{!c.handleSuccess}" />
</aura:component>

Controller:
({
    handleSuccess : function(component, event, helper) {
        component.find('notifLib').showToast({
            "variant": "success",
            "title": "Computer Created",
            "message": "Record ID: " + event.getParam("id")
        });
    }
})

Output:
User-added image
This is the first time am working with Lightnng component. Any help with coding is much appreciated.
ShirishaShirisha (Salesforce Developers) 
Hi Pinky,

Greetings!

Can you please the sample code for hide/show the input fields in lightning component:

https://salesforce.stackexchange.com/questions/240059/how-to-display-hide-fields-in-lightning-component-using-javascript

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
pinky1pinky1
Hi Shirisha,

I have seen the Link and think that doesnt work with my scenario because when i select Carrier Account aka Account which is a lookup object i need to see if that Account Industry is Energy or not. If it's Energy then Populate Price__c field on the Page. Can you help me with the code for my scenario? 
pinky1pinky1
@everyone Any help with code will be appreciated.