0

I asked a question before this one here. The answer there helped solve it but that is introducing a new problem which is that the picklist values are having blank values for each new row and it also erases the value from the dependent picklist field.

Here Type is controlling picklist and reason is dependent picklist.

First row works fine, Screenshot 1.

Adding another row removes the dependent picklist value from the first row and second row has no picklist values. Screenshot 2.

No values in Controlling picklist.. screenshot 3

Component :

<aura:component implements="force:appHostable, 
    flexipage:availableForAllPageTypes,
    flexipage:availableForRecordHome,
    force:hasRecordId" access="global" controller="Nigoemailcommunication" >
<aura:attribute name="recordId" type="String" />

 <!-- PAGE HEADER -->
    <lightning:layout class="slds-page-header slds-page-header--object-home">
       <lightning:layoutItem>
        <lightning:icon iconName="standard:scan_card" 
     alternativeText="primaryinfo"/>
    </lightning:layoutItem>
    <lightning:layoutItem padding="horizontal-small">
        <div class="page-section page-header">
            <h1 class="slds-text-heading--label">NIGO Email 
          Communication</h1>
            <h2 class="slds-text-heading--medium">Primary Information</h2>
        </div>
    </lightning:layoutItem>
    </lightning:layout>

   <aura:attribute name="newCar" type="Childcontact__c" default="{ 
   'sobjectType': 'Childcontact__c','   PrimaryInformation__c': 
    '','Status__c': '','Rejected_Type__c': 
   '','Deadline__c':'','Rejected_Reason__c': ''}"/>
  <aura:attribute name="newCarMap" type ="Map" ></aura:attribute>
  <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
 <div class="slds-m-around--xx-large">
 <div class="slds-float_left slds-p-bottom_small">
   <h1 class="slds-page-header__title">Add Row 
    <lightning:buttonIcon iconName="utility:add"  size="large" variant="bare" 
    alternativeText="Add" onclick="{!c.handleAddcarClick}"/>
    </h1>
    </div>
    <div class="container-fluid">        
    <table class="slds-table slds-table_bordered slds-table_cell-buffer">
    <tbody>      
             <lightning:recordEditForm aura:id="CarCreateForm" 
             objectApiName="Childcontact__c" >
                <aura:iteration items="{!v.newCarMap}" var="acc" 
               indexVar="index">
            <tr>
                <td> 
                    {!index + 1}
                </td>
                <td>
                    <lightning:inputField fieldName="Status__c"> 
               </lightning:inputField>
                </td>
                <td>
                    <lightning:inputField fieldName="Rejected_Type__c"> 
               </lightning:inputField>
                </td>
                <td>
                    <lightning:inputField  fieldName="Rejected_Reason__c"> 
                </lightning:inputField>
                </td>
                   <!--<c:LightningDependentPicklistCmp/>-->
                <td style="padding-top: 27px;padding-left: 48px;">
                    <a onclick="{!c.removeRow}" data-record="{!index}">
                        <lightning:icon iconName="utility:delete" 
                   size="small" alternativeText="Delete"/>
                        <span class="slds-assistive-text">Delete</span>
                    </a>
                </td>
            </tr>
                    </aura:iteration>
           </lightning:recordEditForm>

         </tbody>
         </table>

         </div>
         </div>

         </aura:component>

Controller :

({
doInit : function(component, event, helper) {
     helper.addcar(component);
},

parentFieldChange : function(component, event, helper) {
    var controllerValue = component.find("parentField").get("v.value");// We can also use event.getSource().get("v.value")
    var pickListMap = component.get("v.pickListMap");

    if (controllerValue != '--- None ---') {
         //get child picklist value
        var childValues = pickListMap[controllerValue];
        var childValueList = [];
        childValueList.push('--- None ---');
        for (var i = 0; i < childValues.length; i++) {
            childValueList.push(childValues[i]);
        }
        // set the child list
        component.set("v.childList", childValueList);

        if(childValues.length > 0){
            component.set("v.disabledChildField" , false);  
        }else{
            component.set("v.disabledChildField" , true); 
        }

    } else {
        component.set("v.childList", ['--- None ---']);
        component.set("v.disabledChildField" , true);
    }
},
removeRow: function(component, event, helper) {
    //Get the account list
    var accountList = component.get("v.contactList");
    //Get the target object
    var selectedItem = event.currentTarget;
    //Get the selected item index
    var index = selectedItem.dataset.record;
    accountList.splice(index, 1);
    component.set("v.contactList", accountList);
},

save: function(component, event, helper) {
    if (helper.validateAccountList(component, event)) {
        helper.saveAccountList(component, event);
    }
},
handleAddcarClick : function(component,event,helper){
    helper.addcar(component);
}
})

Helper :

({
addcar : function(component) {
var newCarobjmap = component.get("v.newCarMap");
 var carobj = component.get("v.newCar");
   console.log('carobj'+carobj);
     if(!$A.util.isEmpty(newCarobjmap)){ 
        newCarobjmap.push(carobj);
        component.set("v.newCarMap",newCarobjmap) ;
        }else {    

            component.set("v.newCarMap",[].concat(carobj)) ;
        }
}
})
  • did you get dependent picklist field values after choose controlling picklistfield value or not? after choose controlling field it should get automatically – sdandamud1 May 21 at 16:05
  • yes dependent picklist value came in the first row but in the second one even the controlling one was blank. – apple123 May 21 at 16:05
  • you mean no values to choose in controlling PF other than --None--? – sdandamud1 May 21 at 16:07
  • Yes correct. I will update the question with an image of that. Updated question with Image. – apple123 May 21 at 16:08
  • which one CF and which one DF? – sdandamud1 May 21 at 16:19
0

For anyone who might face this issue, here's how I got it working. Here's another question I had asked.

Component :

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="Nigoemailcommunication" >
    <aura:attribute name="recordId" type="String" />

     <!-- PAGE HEADER -->
    <lightning:layout class="slds-page-header slds-page-header--object-home">
        <lightning:layoutItem>
            <lightning:icon iconName="standard:scan_card" alternativeText="primaryinfo"/>
        </lightning:layoutItem>
        <lightning:layoutItem padding="horizontal-small">
            <div class="page-section page-header">
                <h1 class="slds-text-heading--label">NIGO Email Communication</h1>
                <h2 class="slds-text-heading--medium">Primary Information</h2>
            </div>
        </lightning:layoutItem>
    </lightning:layout>

 <aura:attribute name="docList" type="Docman_Communication__c[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div class="slds-m-around--xx-large">
<div class="slds-float_left slds-p-bottom_small">
    <h1 class="slds-page-header__title">Add Row 
        <lightning:buttonIcon iconName="utility:add"  size="large" variant="bare" alternativeText="Add" onclick="{!c.handleAddrowClick}"/>
    </h1>
</div>
<div class="container-fluid">        
    <table class="slds-table slds-table_bordered slds-table_cell-buffer">
        <tbody>     
            <aura:iteration items="{!v.docList}" var="acc" indexVar="index">
                <lightning:recordEditForm aura:id="docmancommunicationform" objectApiName="Docman_Communication__c" >                    
                <tr>
                    <td> 
                        {!index + 1}
                    </td>
                    <td>
                        <lightning:inputField aura:id="select" fieldName="Select"/>
                    </td>
                    <td>
                        <lightning:inputField aura:id="primaryname" fieldName="PrimaryInformation__c"></lightning:inputField>
                    </td>
                    <td>
                        <lightning:inputField fieldName="Status__c" value="{!acc.Status__c}"></lightning:inputField>
                    </td>
                    <td>
                        <lightning:inputField fieldName="Rejected_Type__c" value="{!acc.Rejected_Type__c}"></lightning:inputField>
                    </td>
                    <td>
                        <lightning:inputField  fieldName="Rejected_Reason__c" value="{!acc.Rejected_Reason__c}"></lightning:inputField>
                    </td>
                    <td>
                        <lightning:inputField fieldName="Dealine__c" value="{!acc.Dealine__c}"/>
                    </td>
                       <!--<c:LightningDependentPicklistCmp/>-->
                    <td style="padding-top: 27px;padding-left: 48px;">
                        <a onclick="{!c.removeRow}" data-record="{!index}">
                            <lightning:icon iconName="utility:delete" size="small" alternativeText="Delete"/>
                            <span class="slds-assistive-text">Delete</span>
                        </a>
                    </td>
                </tr>
                </lightning:recordEditForm>
                </aura:iteration>


        </tbody>
    </table>

</div>
    </div>

</aura:component>

Controller :

({
    doInit : function(component, event, helper) {
         helper.addrow(component);
    },
    handleAddrowClick : function(component,event,helper){
        helper.addrow(component);
   },
    removeRow: function(component, event, helper) {
        //Get the account list
        var docList = component.get("v.docList");
        //Get the target object
        var selectedItem = event.currentTarget;
        //Get the selected item index
        var index = selectedItem.dataset.record;
        docList.splice(index, 1);
        component.set("v.docList", docList);
    }
})

Helper :

({
    addrow: function(component) {
     var docobj = component.get("v.docList");
       console.log('docobj'+JSON.stringify(docobj));
        var rowItemList = component.get("v.docList");
        rowItemList.push({ 'sobjectType': 'Docman_Communication__c','Status__c': '','Rejected_Type__c': '','Rejected_Reason__c': '',
                           'Deadline__c':''});
        component.set("v.docList", rowItemList);
    }
})

Couple of things I learned,

  • In the the fieldname is always the API Name.
  • Put the RecordEditForm under
  • To get the default behavior of controlling and dependent picklist fields, you need to use <lightning:recordEditForm aura:id="docmancommunicationform" objectApiName="Docman_Communication__c" >. Thanks to @sdandamud1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.