You need to sign in to do that
Don't have an account?
leduc dat
Can't save record of child component is nested in parent component
Hi all,
I am having an issue with saving record of lightning:recordEditForm with nested component.
I have component A which will display content depending on currentuserID. In this case, component A will call component B to open a new modal popup. The problem occurs when I press the save button, it shows a windows message like below image.
I tested component B by overriding 'new' standard action, but no errors occurred and record is saved.
So, I think component B doesn't work when nested in another component, but I don't know how to fix it properly.
I'm new to aura so I don't understand it very well.
Someone please help me. Thank you
I am having an issue with saving record of lightning:recordEditForm with nested component.
I have component A which will display content depending on currentuserID. In this case, component A will call component B to open a new modal popup. The problem occurs when I press the save button, it shows a windows message like below image.
I tested component B by overriding 'new' standard action, but no errors occurred and record is saved.
So, I think component B doesn't work when nested in another component, but I don't know how to fix it properly.
I'm new to aura so I don't understand it very well.
Someone please help me. Thank you
--------------Component A( testNestedComponent.cmp)---------------------------------- <aura:component implements="lightning:actionOverride,force:hasRecordId,force:hasSObjectName"> <!-- attributes --> <aura:attribute name="checkUser" type="Boolean" default="true" /> <aura:attribute name="userId" type="User" /> <!-- handlers--> <aura:handler name="init" value="{! this }" action="{! c.init }" /> <aura:if isTrue="{!v.checkUser}"> <lightning:listView aura:id="listViewDoctors" objectApiName="DoctorPersonalInfo__c" listName="AllDoctorPersonalInfo" rows="10" showSearchBar="true" showActionBar="false" enableInlineEdit="false" showRowLevelActions="false" /> <aura:set attribute="else"> <c:createNewDoctorPopupModal /> </aura:set> </aura:if> </aura:component>
-----------------Component B( createNewDoctorPopupModal.cmp)------------------- <aura:component controller="createNewDoctor_Apex" implements="force:hasRecordId,flexipage:availableForAllPageTypes,lightning:actionOverride,force:lightningQuickAction"> <lightning:workspaceAPI aura:id="workspace" /> <aura:attribute name="loading" type="Boolean" default="false" /> <aura:attribute name="isModalOpen" type="boolean" default="true" /> <aura:handler name="init" value="{!this}" action="{!c.init}" /> <div class="slds-m-around_xx-large"> <aura:if isTrue="{!v.isModalOpen}"> <lightning:recordEditForm objectApiName="DoctorPersonalInfo__c" aura:id="newRecordDoctorInfo" onsuccess="{!c.handleSuccess}" onsubmit="{!c.handleSubmit}" onerror="{!c.handleError}" onload="{!c.handleLoad}"> <lightning:messages aura:id="OppMessage" /> <!-- Modal/Popup Box starts here--> <section role="dialog" tabindex="-1" aria-hidden="false" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-backdrop_open"> <div class="slds-modal__container"> <!-- Modal/Popup Box Header Starts here--> <header class="slds-modal__header"> <lightning:buttonIcon iconName="utility:close" onclick="{! c.closeModel }" alternativeText="close" variant="bare-inverse" class="slds-modal__close" /> <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">{!'新規 医師情報'} </h2> </header> <!--Modal/Popup Box Body Starts here--> <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1"> <div class="slds"> <div class="row"> <div class="slds-section__title slds-theme_shade" style="padding: 3px;"> <h3 style="font-size: 1rem;" title="">Information</h3> </div> <div class="slds-grid"> <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large "> <lightning:inputField class=".slds-size_1-of-2" fieldName="doctorName__c" aura:id="newDoctorInfoField" /> </div> </div> <div class="slds-grid"> <div class="slds-size_6-of-12 slds-p-left_xx-large slds-p-horizontal_x-large "> <lightning:inputField class=".slds-size_1-of-2" fieldName="doctorGender" aura:id="newDoctorInfoField" required="true" /> </div> </div> </div> </div> </div> <!--Modal/Popup Box Footer Starts here--> <footer class="slds-modal__footer"> <lightning:button variant="neutral" label="Cancel" title="Cancel" onclick="{! c.closeModel }" /> <lightning:button variant="brand" label="Save" title="OK" type="submit" /> <!-- onclick="{!c.submitDetails}" --> </footer> </div> </section> <div class="slds-backdrop slds-backdrop_open"></div> <aura:if isTrue="{!v.loading}"> <lightning:spinner alternativeText="Loading" /> </aura:if> </lightning:recordEditForm> </aura:if> </div> </aura:component>
For another query that you have, actually userId is never an instance of DoctorPersonalInfo__c object but an Id only. So you can't save or insert this in your APEX class createNewDoctor_Apex. Also any call to APEX class via aura is asynchronous in nature so you may have to rewrite the record update logic once record is created.
So I would suggest you to remove this logic from APEX and aura and create a workflow rather and use workflow field update to stamp the current user ID on the custom field(User_Id__c for example) of DoctorPersonalInfo__c.
Hope this answers your question. If so please can you make this as best answer. Thanks.
All Answers
I see you are uning lightning:inputfield and there you are giving the fieldname
<lightning:inputField class=".slds-size_1-of-2" fieldName="doctorGender" aura:id="newDoctorInfoField" required="true" />
doctorGender is not a standard field, can you please try by giving field API name here that ends with __c and check your code then.
Thank you for answering. It's my typo mistake.
Even i change to doctorGender__c , the error is not gone away
Thank you, After comment out "action.setParams({ userId : $A.get("$SObjectType.CurrentUser.Id") });", it works properly.
Actually i want to save currentUserId with lightning:recordEditForm submit but it doenst work.
Can you help me see it? it's like below:
--------------Component B( createNewDoctorPopupModalHelper.js))----------------------------------
....
if (!showValidationError) {
var action = cmp.get("c.saveUserID");
action.setParams({ userId : $A.get("$SObjectType.CurrentUser.Id") });
component.set('v.loading', true);
component.find("newRecordDoctorInfo").submit();
} else {
component.find('OppMessage').setError(vaildationFailReason);
component.set('v.loading', false);
createNewDoctor_Apex
For another query that you have, actually userId is never an instance of DoctorPersonalInfo__c object but an Id only. So you can't save or insert this in your APEX class createNewDoctor_Apex. Also any call to APEX class via aura is asynchronous in nature so you may have to rewrite the record update logic once record is created.
So I would suggest you to remove this logic from APEX and aura and create a workflow rather and use workflow field update to stamp the current user ID on the custom field(User_Id__c for example) of DoctorPersonalInfo__c.
Hope this answers your question. If so please can you make this as best answer. Thanks.