You need to sign in to do that
Don't have an account?
Francis A.
Alternate implementation of dependent picklists inside an aura:iteration in Lightning
I'm looking at alternate ways of implementing dependent picklists that are within an aura:iteration. Basic processing is that I am displaying a list of records with a couple of fields rendered as input (the controlling and dependent picklist). Unfortunately, this did not work for me and I've tried:
- lightning:recordEditForm - The form renders the fields vertically and both picklists need to be rendered at the same time, which is not the case for an iterating list of records and fields.
- ui:inputselect, but hit a snag where aura:id can not take in dynamically generated values and therefore the controller does not have any way to determine what specific inputselect tag in the list of records it will try to rerender.
<aura:iteration items="{!v.displayDTORecord}" var="item"> <tr class="slds-hint-parent"> <aura:iteration items="{!item.lstFieldVal}" var="f"> <aura:if isTrue="{!f.field_api == 'Name'}"> <td role="gridcell" data-label="{!f.field_api}"> <div class="slds-truncate" title="{!f.value}"> <a href="javascript:void(0);" id="{!item.recId}" onclick="{!c.doRedirect}"><span>{!f.value}</span></a> </div> </td> <aura:set attribute="else"> <td role="gridcell" data-label="{!f.field_api}"> <aura:if isTrue="{!f.field_api != 'Additional_Details__c'}"> <aura:if isTrue="{!f.inputField == false}"> <div class="no-text-overflow slds-truncate" title="{!f.value}">{!f.value}</div> <aura:set attribute="else"> <aura:if isTrue="{!f.field_api == 'Offer_Status__c'}"> <!-- <div class="slds-form-element"> <div class="slds-select_container"> <ui:inputSelect aura:id="{!f.field_api_idx}" change="{!c.onControllerTOFieldChange}" value="{!f.value}"/> </div> </div> --> <lightning:select name="mySelect" label="" aura:id="{!f.field_api_idx}" value="{!f.value}"> <aura:iteration items="{!v.options}" var="item"> <option text="{!item.label}" value="{!item.value}" selected="{!item.selected}"/> </aura:iteration> </lightning:select> <aura:set attribute="else"> <div class="slds-form-element"> <div class="slds-select_container"> <ui:inputSelect aura:id="Offer_Outcome__c" disabled="{!v.isDependentDisableTO}" change="{!c.onDependentTOFieldChange}" value="{!f.value}" /> </div> </div> </aura:set> </aura:if> </aura:set> </aura:if>Is there a workaround or something that you would've similarly implemented successfully? Thanks.
An alternative to <lightning:inputField> ?
https://developer.salesforce.com/docs/component-library/bundle/lightning:inputField/documentation
Dependent Picklist Example:
This example uses LeadSource as the controlling field and Level__c as the dependent field for a dependent picklist.
<lightning:inputField> is not as easy to use as <apex:inputField> for VFP (many understandable constraints).
https://success.salesforce.com/ideaView?id=08730000000Dom1AAC
1) This famous blog tried to solve many missing features of LEX based here on the real metadata of the dependant picklists but it is difficult to do completely (read the comments at the end of the page for the recent bugs). Even for Salesforce, it is difficult (<lightning:inputField> is recent and still difficult to use)
http://sfdcmonkey.com/2017/02/18/dependent-picklist-fields-lightning-component/
2) An easy smart alternative if you don't use the standard dependant picklists of Salesforce but your own lists (here Country, Citiy)
The code is short and works fine (all is done by the structure of the lists and the single event onchange="{!c.PickChange}"
http://www.minerva18.com/blog/creating-dependent-picklists-in-lightning-components/
There are many alternatives on the internet for the dependant picklists wiht jQuery and so on.
Your component is not enough if you want some help.
It is your JS controller that is not correct and it is the interesting part that we would like to see.
Controller
Helper
My problems are: 1) looking at the ui:inputSelect(s), I am unable to reference an index in aura:id that I am able to component.find back in the controller to pass back the picklist values. 2) I believe same thing will happen to the lightning:select because I will still need to reference an aura:id.
So I am stuck, but is there a different way to implement this if I did hit an aura:id limitation?