2

I am having this section in lightning:recordEditForm.

<aura:attribute name="quoteRecord" type="SBQQ__Quote__c" default="{'sobjectType': 'SBQQ__Quote__c',
    'SBQQ__Primary__c': false
}"/>
<lightning:recordEditForm aura:id="quoteForm" objectApiName="SBQQ__Quote__c" onload="{!c.handleOnload}" 
    onsubmit="{!c.handleOnSubmit}">
    <lightning:messages/>
    <lightning:inputField aura:id="accountId" fieldName="SBQQ__Account__c" value="{!v.quoteRecord.SBQQ__Account__c}"/>
    <lightning:inputField aura:id="isPrimary" fieldName="SBQQ__Primary__c" value="{!v.quoteRecord.SBQQ__Primary__c}"/>
    <lightning:outputField aura:id="opportunityId" fieldName="SBQQ__Opportunity2__c" value="{!v.quoteRecord.SBQQ__Opportunity2__c}"/>
    <lightning:inputField aura:id="salesRep" fieldName="SBQQ__SalesRep__c" value="{!v.quoteRecord.SBQQ__SalesRep__c}"/>
    <lightning:inputField aura:id="currency" fieldName="CurrencyIsoCode" value="{!v.quoteRecord.CurrencyIsoCode}"/>
</lightning:recordEditForm>

I set up the value via init or onLoad methods:

doInit : function(component, event, helper) {
    var oppId = component.get("v.recordId");
    var action = component.get("c.initQuote");

    action.setParams({
        oppId: oppId
    });

    action.setCallback(this, function(response) {
        result = response.getReturnValue();
        component.set("v.quoteRecord", result);
    });

    $A.enqueueAction(action);
}

Apex controller:

 public static SBQQ__Quote__c initQuote(String oppId) {
     Opportunity opp = [Select Id, CurrencyIsoCode, ownerId, accountId From Opportunity Where Id = :oppId];
     List<PriceBook2> pb = [Select Id, Name From PriceBook2 Where Name = 'Standard Price Book'];
     SBQQ__Quote__c q = new SBQQ__Quote__c(
         SBQQ__Opportunity2__c = oppId, 
         SBQQ__PriceBook__c = pb[0].Id,
         SBQQ__Account__c = opp.accountId,
         SBQQ__SalesRep__c = opp.ownerId,
         SBQQ__Primary__c = false,
         CurrencyIsoCode = opp.CurrencyIsoCode
     );

But strangely, only the init value of account has been set on the editRecordForm. I have checked the attribute's value in the debug log, it is all correctly set.

I have tried doing the initialization in both init and onload methods. But neither works. I have even tried with component.find("auraId").set("v.value", value). But still doesn't seem to work in this case.

I am wondering whether this is due to inputField's type. Any suggestions?

8
  • Do you have the fields in the SOQL from where you are returning the results to the component?
    – Jayant Das
    Jan 30, 2019 at 3:00
  • @JayantDas I added the apex controller init code as requested
    – Lance Shi
    Jan 30, 2019 at 3:04
  • And you do get results based on your SOQL in the Apex? Also is this the exact Apex method, e.g., I don't see @AuraEnabled and a return statement.
    – Jayant Das
    Jan 30, 2019 at 3:07
  • @JayantDas No, I created a new quote. It is not in the database
    – Lance Shi
    Jan 30, 2019 at 3:08
  • @JayantDas Yes, the quote value returned from the apex controller is perfect. I debugged in javascript and also tested the attribute back in another apex class by passing the quote attribute. Both are fine
    – Lance Shi
    Jan 30, 2019 at 3:11

1 Answer 1

2

I just find it out myself. The reason is pretty strange though - if I remove the lightning:outputField, everything just populates smoothly without any issue.

So it is actually the lightning:outputField which blocks default values from populating up. Considering lightning:recordEditForm won't respect disabled attribute for the inputField, I find this really funny.

You must log in to answer this question.

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