0

I have a table below in a lightning page. enter image description here I have selected first two recipients But the problem is that those recipients are going back to none. They are contacts of an account. This was working for years without any issue But since two days it's broken. This is the same thing with all drop downs in a different org too with the same logic shown below.

<tbody>
<aura:iteration items="{!v.recipientList}" 
                var="recipient">
    <tr class="slds-hint-parent" 
        id="{!recipient.rowCount}">
        <td role="gridcell" class="slds-cell-edit mtd">
            <span>
                {!recipient.rowCount}
            </span>
        </td>
        <td role="gridcell">
            <div>
                <select class="selectEle" 
                        id="{!'recCo-'+recipient.rowCount}" 
                        onchange="{!c.changedRecipContact}">
                    <option selected="selected" 
                            value="None">-None-</option>
                    <aura:iteration items="{!v.consList}" 
                                    var="cons">
                        <aura:if isTrue="{!(recipient.contact.Id == cons.id)}" >
                            <option selected="selected" 
                                    value="{!cons.id}">{!cons.name}</option>
                            <aura:set attribute="else">
                                <option value="{!cons.id}">{!cons.name}</option>
                            </aura:set>
                        </aura:if>
                    </aura:iteration>
                </select> 
            </div>
        </td>
        .
        .
        .
    </tr>
</aura:iteration>
</tbody>

CONTROLLER:

changedRecipContact : function(component, event, helper){
    component.set("v.loadScreen",true);
    var selectId = event.target.id;
    console.log('selected row:: '+ selectId);
    var rowInd = selectId.substring(6);
    var selectedContactId = document.getElementById(selectId).value;
    console.log('selected contact ID:: '+ selectedContactId+' rowCount:: '+rowInd);

    var action = component.get('c.contactChanged');
    action.setParams({"conList":JSON.stringify(component.get("v.recipientList")),
                      "contactId":selectedContactId,
                      "rowCount":rowInd});
    action.setCallback(this, function(a) {
        var state = a.getState();
        console.log('state from contactChanged:: '+state);
        if(state === "SUCCESS"){
            component.set("v.recipientList",a.getReturnValue());        
        }
        component.set("v.loadScreen",false);
    });
    $A.enqueueAction(action);
},

Server-side code:

@auraEnabled
public static List<contactWrapper> contactChanged(String conList, String contactId, String rowCount){
    List<contactWrapper> contactList = (List<contactWrapper>) JSON.deserialize(conList, List<contactWrapper>.class);

    List<contactWrapper> conWrapper = new List<contactWrapper>();
    contactWrapper obj = new contactWrapper();

    for(contactWrapper cons:contactList){
        conWrapper.add(cons);
    }
    contact con = new contact();

    if(conWrapper.get(Integer.valueOf(rowCount)-1)!=null){
        obj= conWrapper.get(Integer.valueOf(rowCount)-1);
        obj.rowCount = rowCount;
        con = [SELECT id, Name, Phone, Email FROM contact WHERE id=: contactId];
        obj.contact = con;
        obj.Email = con.email;
        obj.scope = 'Signer';
    }
    return conWrapper;
}

recipientList is a wrapper object which holds contact, email, scope etc.. IT IS STILL WORKING FINE IN FIREFOX BROWSER. But it's not working properly in chrome browser and behaving like screenshot shown above. Can anyone please help me why this is misbehaving in chrome and fix it. This is not happening in just one workstation.

Thanks in advance.

0

I would add an attribute and update the <select> tags;

<aura:attribute name="selectedContactId" type="String"/>
<!-- rest of code ommited -->
               <select class="selectEle" 
                        id="{!'recCo-'+recipient.rowCount}" 
                        onchange="{!c.changedRecipContact}"
                        value="{!v.selectedContactId}"
                >
                    <option selected="{!v.selectedContactId == 'None'}" 
                            value="None">-None-</option>
                    <aura:iteration items="{!v.consList}" var="cons">
                            <option value="{!cons.id}" 
                                    selected="{!v.cons.id == v.selectedContactId}"
                            >
                                  {!cons.name}
                            </option>
                    </aura:iteration>
                </select> 

I've had a similar issue with lightning:select and this is how I solved it

1
  • That is a table and there are more than 1 selected Contact. How can a single selectContactId attribute can set each row's different contact? Have you implemented this in your environment in a TABLE? – AshSFcloud Jun 26 '20 at 12:53
0

try below code

CONTROLLER

changedRecipContact : function(component, event, helper){
component.set("v.loadScreen",true);
var selectId = event.target.id;
var rowInd = selectId.substring(6);
var selectedContactId = document.getElementById(selectId).value;
var recipientList = component.get("v.recipientList");
var selectedRecipient = recipientList[parseInt(rowInd) - 1];
var action = component.get('c.contactChanged');
action.setParams({"conList":JSON.stringify(selectedRecipient),
                  "contactId":selectedContactId,
                  "rowCount":rowInd});
action.setCallback(this, function(a) {
    var state = a.getState();
    console.log('state from contactChanged:: '+state);
    if(state === "SUCCESS"){
        recipientList[parseInt(rowInd) - 1] = a.getReturnValue();
        component.set("v.recipientList", recipientList);        
    }
    component.set("v.loadScreen",false);
});
$A.enqueueAction(action);
},

Server-side code

  @auraEnabled
public static contactWrapper contactChanged(String conList, String contactId, String rowCount){
    contactWrapper objRecipient = (contactWrapper) JSON.deserialize(conList, contactWrapper.class);
    objRecipient.rowCount = rowCount;
    contact con = new contact();
    con = [SELECT id, Name, Phone, Email FROM contact WHERE id=: contactId];
    objRecipient.contact = con;
    objRecipient.Email = con.email;
    objRecipient.scope = 'Signer';
    return objRecipient;
}
1
  • Gopalakrishna, It's a no go. It seems like we are just inserting obj in list in a different way. Issue is the same with above approach. – AshSFcloud Jun 29 '20 at 7:55

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.