0

I am having input fields inside my recordEditForm. When i try to run the component it's not calling the onload event handler. I don't want to put any lightning:inputField into it. Because I don't need standard UI. Also receiving error on submit.Here is my sample code.

newContact.cmp

<aura:component >
    <aura:attribute name="simpleNewContact" type="Object"/>
    <lightning:recordEditForm
            onload="{!c.handleLoad}"
            onsubmit="{!c.handleSubmit}" 
            onerror="{!c.handleError}"
            onsuccess="{!c.handleSuccess}"
            objectApiName="Contact" aura:id="myRecordForm">
        <div class="Create Contact">
            <lightning:card iconName="action:new_contact" title="Create Contact">
                <div class="slds-p-horizontal--small">
                    <lightning:input aura:id="contactField" label="First Name" value="{!v.simpleNewContact.FirstName}"/>
                    <lightning:input aura:id="contactField" label="Last Name" value="{!v.simpleNewContact.LastName}"/>
                    <lightning:input aura:id="contactField" label="Title" value="{!v.simpleNewContact.Title}"/>
                    <br/>
                    <lightning:button label="Save Contact" type="submit" variant="brand"/>
                </div>
            </lightning:card>
        </div>
    </lightning:recordEditForm>

    <!-- Display Lightning Data Service errors -->
    <aura:if isTrue="{!not(empty(v.newContactError))}">
        <div class="recordError">
            {!v.newContactError}</div>
    </aura:if>
</aura:component>

newContactController.js

({
    handleLoad : function(component, evnet, helper){
        console.log('loaded');
    },
    handleSuccess : function(component, evnet, helper){
        var payload = event.getParams().response;
        alert(payload.id);
    },
    handleError:function(component, evnet, helper){
        var error = event.getParam('error');
        alert(JSON.stringify(error));
    },
    handleSubmit : function(component, evnet, helper){
        event.preventDefault();   
        var fields = event.getParam('fields');
        console.log(fields);
        component.find("myRecordForm").submit(component.get("v.simpleNewContact"));
    }
})

Any suggestions ?

0

If you don't need the "standard UI", use force:recordData instead. You can load and save records using this component without requiring a UI.

  • here is what I faced in force:recordData before moving into this salesforce.stackexchange.com/questions/262811/… – Rajesh May 17 at 14:08
  • @Rajesh force:recordData is more likely the correct method, but your other question will need to be solved. I don't have a mobile setup at the moment, so I don't think I have an answer to the situation, but hopefully you'll find the answer you need. – sfdcfox May 17 at 14:31

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.