2

The recordEditForm is not supposed to need the Lightning data service provided by recordData however in the below example the only time fields beyond the first one show up are if I also include the recordData component.

Example:

<aura:component description="Example" access="global">

<aura:attribute name="componentError" type="String" access="private"
                description="An error message to display instead of the component"/>

<aura:attribute name="payeeRecordId" type="String" access="global"/>
<aura:attribute name="payeeObjectType" type="String" required="true" access="global" default="Contact"/>
<aura:attribute name="payeeRecordFields"type="Object" access="private"/>
<aura:attribute name="payeeRecordFieldList" type="String[]" access="global" default="FirstName, LastName"/>

<aura:attribute name="payeeRecord" type="Object" access="private"/>


<aura:attribute name="payeeRecordError" type="String" access="private"/>



<aura:if isTrue="{!not(empty(v.componentError))}">

    <div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_error" role="alert">
        <span class="slds-assistive-text">Error</span>
        <span class="slds-icon_container slds-icon-utility-error slds-m-right_x-small"
              title="Description of icon when needed">
            <lightning:icon variant="inverse" iconName="utility:error" size="x-small"/>
        </span>
        <h2>{!v.componentError}</h2>
    </div>

    <aura:set attribute="else">
        <force:recordData aura:id="payeeRecord"
                          layoutType="FULL"
                          recordId="{!v.payeeRecordId}"
                          targetRecord="{!v.payeeRecord}"
                          targetFields="{!v.payeeRecordFields}"
                          fields="{!v.payeeRecordFieldList}"
                          targetError="{!v.payeeRecordError}"
                          mode="VIEW"/>

        <lightning:recordEditForm recordId="{!v.payeeRecordId}" objectApiName="{!v.payeeObjectType}">
            <aura:iteration items="{!v.payeeRecordFieldList}" var="f">
                <lightning:inputField fieldName="{!f}"/>
            </aura:iteration>
        </lightning:recordEditForm>

    </aura:set>
</aura:if>

Output

With Record Data

However if I remove the force:recordData component only the first field gets output

Without recordData

Goal

I am trying to provide a way for the user of the component to specify which fields get presented for input.

  • Eric - found a reference for this in the documentation, updated in answer. Seems that was the case here. – Jayant Das Jan 30 '19 at 23:34
2

UPDATE

Based on your latest edits, you have the attribute populated as below:

<aura:attribute name="payeeRecordFieldList" type="String[]" access="global" 
                default="FirstName, LastName"/>

Having spaces in the field names did not work for me. Later, referring to the excerpt from the documentation, seems this may have been the issue here.

To set a default value, surround comma-separated values with []; for example default="['red', 'green', 'blue']". Setting a default value without square brackets is deprecated and can lead to unexpected behavior.

This is what I think was happening in this case when being used with force:recordData (LDS) implementation. LDS would have taken care of removing spaces from the attribute payeeRecordFieldList And that without LDS because the field names are separated with a comma and a space in there, it never worked because of the explanation as in documentation.

In my example below, the field names worked without having spaces between it and then later with the approach as mentioned in the documentation.


You don't need a force:recordData implementation here. As long as your attribute payeeRecordFieldList is populated and consists of the fields you want to display on your form, you should be able to render those fields in your lightning:recordEditForm.

You may like to verify if the attribute payeeRecordFieldList is populated correctly or not.

As an example, I used your code with few minor modifications and removed the force:recordData piece and after declaring the attribute as below, the fields were rendered appropriately.

<!-- other code -->
<aura:attribute name="payeeRecordFieldList" type="String[]"  access="global" 
                default="FirstName,LastName,AccountId" />

OR

<aura:attribute name="payeeRecordFieldList" type="String[]"  access="global" 
                default="['FirstName'], ['LastName'], ['AccountId']" />

<!-- other code -->
<!-- removed LDS force:recordData implementation -->
<lightning:recordEditForm recordId="{!v.payeeRecordId}" objectApiName="{!v.payeeObjectType}">
    <aura:iteration items="{!v.payeeRecordFieldList}" var="f">
        <lightning:inputField fieldName="{!f}"/>
    </aura:iteration>
</lightning:recordEditForm>

enter image description here

| improve this answer | |
  • It is populated, the values are passed when the component is used. – Eric Jan 30 '19 at 22:43
  • I really don't see any other issue unless the attribute is not populated and that I confirmed it. I though see a space in the field names in the attribute, and that if I had it that way, it did not work. Can you try removing the spaces between the field names and try? – Jayant Das Jan 30 '19 at 22:56
  • I just figured that out. With the spaces it WORKS with the recordData but does not work without it. When I remove the spaces it works both with and without the recordData. Not sure what the spaces do to require it to use recordData.... – Eric Jan 30 '19 at 22:59
  • I think if you had force:recordData, LDS populated the attribute thus overriding the spaces in there, so it always used the values as populated by LDS. Then when you removed LDS, because the field names had spaces, it never worked. – Jayant Das Jan 30 '19 at 23:00

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.