Skip to main content

I am using LDS to display and edit data in lightning component but that doesn't seem to be working. 

 

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes,force:hasRecordId" access="global" controller="MDP_AdCampaignUtil">

    <aura:handler event="c:OpportunityClickEvent" action="{!c.showOpportunity}"/>    

    <!--<aura:handler name="onSaveSuccess" event="force:recordSaveSuccess" action="{!c.saveSuccess}"/>-->

    <!-- create 2 aura handler with waiting and donewaiting events--> 

    <aura:handler event="aura:waiting" action="{!c.showSpinner}"/>

    <aura:handler event="aura:doneWaiting" action="{!c.hideSpinner}"/>

    

    <!--create component attributes -->

    <aura:attribute name="Spinner" type="boolean" default="false"/>

    <aura:attribute type="Opportunity" name="printOpp" access="global" default="{'sobjectType':'Opportunity'}"/>

    <aura:attribute type="Boolean" name="editView" default="false"/>

    <aura:attribute type="Boolean" name="detailView" default="false"/>

    <aura:attribute type="Boolean" name="cloneView" default="false"/>

    <!-- Attibutes for LDS -->

    <aura:attribute name="retrievedRecordDisplay" type="Object"/>

    <aura:attribute name="oppRecordDisplay" type="Object"/>

    <aura:attribute name="recordErrorDisplay" type="String"/>

    

    <aura:attribute name="retrievedRecordEdit" type="Object"/>

    <aura:attribute name="oppRecordEdit" type="Object"/>

    <aura:attribute name="recordErrorEdit" type="String"/>

    

    <!--loading spinner start... style=Brand Medium (blue dots)-->

    <aura:if isTrue="{!v.Spinner}">

        <div aura:id="spinnerId" class="slds-spinner_container">

            <div class="slds-spinner--brand  slds-spinner slds-spinner--large slds-is-relative" role="alert">

                <span class="slds-assistive-text">Loading</span>

                <div class="slds-spinner__dot-a"></div>

                <div class="slds-spinner__dot-b"></div>

            </div>

        </div>

    </aura:if>

    <!-- Loading spinner end-->

    Record ID - {!v.recordId}

    Print opp ID - {!v.printOpp.Id}

    <force:recordData aura:id="recordView"

        layoutType="FULL"

        recordId="{!v.printOpp.Id}"

        targetError="{!v.recordErrorDisplay}"

        targetRecord="{!v.retrievedRecordDisplay}"

        targetFields="{!v.oppRecordDisplay}"

        mode="VIEW" />

    

    <force:recordData aura:id="recordEdit"

        layoutType="FULL"

        recordId="{!v.printOpp.Id}"

        targetError="{!v.recordErrorEdit}"

        targetRecord="{!v.retrievedRecordEdit}"

        targetFields="{!v.oppRecordEdit}"

        mode="EDIT" />

    

    <div class="slds-form--stacked slds-tile">

        <aura:if isTrue="{!v.detailView }">

            <div class="slds-form-element">

                <label class="slds-form-element__label"  >Name: </label>

                <div class="slds-form-element__control">

                    <ui:outputText class="slds-input" 

                                   value="{!v.oppRecordDisplay.Opp_Number__c}" />

                </div>

            </div> 

            <div class="slds-form-element">

                <label class="slds-form-element__label" >Amount : </label>

                <div class="slds-form-element__control">

                    <ui:outputTextArea class="slds-input"  

                                       value="{!v.oppRecordDisplay.Amount}"  />

                </div>

            </div> 

            <ui:button aura:id="editRecord" buttonTitle="Edit" class="button" label="Edit" press="{!c.makeEdit}"/>

        </aura:if>

        

        <aura:if isTrue="{!v.editView }">

            <div class="slds-form-element">

                <label class="slds-form-element__label"  >Name (Editable): </label>

                <div class="slds-form-element__control">

                    <ui:inputText class="slds-input" 

                                  value="{!v.oppRecordEdit.Opp_Number__c}" />

                </div>

            </div> 

            <div class="slds-form-element">

                <label class="slds-form-element__label" >Amount (Editable) : </label>

                <div class="slds-form-element__control">

                    <ui:inputText class="slds-input"  

                                  value="{!v.oppRecordEdit.Amount}"  />

                </div>

            </div> 

            <div class="slds-form-element">

                <ui:button aura:id="saveRecord" buttonTitle="Save" class="button" label="Save" press="{!c.handleSaveRecord}"/>

            </div>

        </aura:if>

        

    </div> 

    

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

        <div class="recordError">

            {!v.recordErrorDisplay}

        </div>

    </aura:if>

    

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

        <div class="recordError">

            {!v.recordErrorEdit}

        </div>

    </aura:if>

</aura:component>

 

Per the trailhead and available documentation, I should be binding my output/ input fields with the "targetFields" attribute of <force:recordData> but when doing so, no value is displayed. In my case, recordId = {!v.printOpp.Id} is populated through the client side controller method which is invoked when the page loads. The same functionality works if I bind the recordId={!v.recordId} where v.recordId is derived from the "aura:page force:hasRecordID".

 

What could I be missing here?

8 commenti
  1. 5 gen 2018, 18:54
    Glad it's working for you now. I can fully appreciate the 'alot of trials' part.
0/9000