0

I am using Lightning and its standard functionality of adding products on an opportunity. I need when the users are selecting the products from Add Products page and click Next; On the Edit Selected Products, a field to show or hide depending on the product type selected previously. I have created the field on the Opportunity Line Item - a Lookup field to the custom object (not ideal).

This is what I have built so far, but it's not working:

<aura:component >
    <aura:attribute name="ProductType" type="String" default="ProductType1" />
     <aura: attribute name ="Customfield" type="String" />

    <lightning:select name="ProductName" value="{! v.ProductType}">
         <option value = "ProductType1">ProductType1</option>
         <option value = "ProductType2">ProductType2</option>
         <option value = "ProductType3">ProductType3</option>
         <option value = "ProductType4">ProductType4</option>

    </lightning:select>


    <aura:if isTrue="{! v.AdType == 'ProductType5' }">

        <lightning:input label="Customfield" value ="{! v.Customfield}" />

    </aura:if>
</aura:component>

*Where ProductType 5 is the type of product, the custom field (lookup field doesn't need to show on the OLI.

If anyone has a bit of time and can provide some help, that would be great.

Thanks a lot in advance.

S

2
  • Hi SSimon , Welcome to SFSE, You have too many problems statements in this big post. Can you target the specifics? Also, its fine to create multiple questions to target specific problem. Commented Jun 21, 2019 at 10:41
  • Hi,Thank you. Yes sure.
    – SSimion
    Commented Jun 21, 2019 at 10:44

1 Answer 1

0

You have lightning:select , whenever you select a value in it, it gets binded to value="{!v.ProductType}

So you have to check that in your aura:if. If productType!="ProductType5" then show your lightning:input

<aura:attribute type="String" name="ProductType"></aura:attribute>
    <aura:attribute type="String" name="Customfield"></aura:attribute>


    <lightning:select name="ProductName" value="{! v.ProductType}" label="productName">
        <option value = "ProductType1">ProductType1</option> 
        <option value = "ProductType2">ProductType2</option>
        <option value = "ProductType3">ProductType3</option>
        <option value = "ProductType4">ProductType4</option>
        <option value = "ProductType5">ProductType5 </option>

    </lightning:select>


    <aura:if isTrue="{! v.ProductType != 'ProductType5' }">

        <lightning:input label="Customfield" value ="{! v.Customfield}" />

    </aura:if>
5
  • Hi, Thank you so much for your reply. I am trying to save this applying all the changes suggested but I am getting this error message - 1,52: Invalid attribute "type": Source. It fails to save. Is it because ProductType is a pick-list field that contains all the types of products?
    – SSimion
    Commented Jun 21, 2019 at 11:39
  • create a new aura app from dev console. Post the above code snippet and try if it works? Commented Jun 21, 2019 at 12:04
  • Hi, I have managed to save the code by creating a new aura, as you suggested, but unfortunately doesn't hide the field for a type of product. Do I need a trigger for this? Thanks a lot.
    – SSimion
    Commented Jun 21, 2019 at 13:30
  • It does for ProductType5? Commented Jun 21, 2019 at 13:31
  • The custom field appears for all ProductTypes, I am afraid. Thanks for your patience. And I want to be able to hide the custom field for one of the producttypes.
    – SSimion
    Commented Jun 21, 2019 at 13:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .