Error handling using aura record edit form

auralightning-aura-componentslightning-recordeditform

Is it possible to remove or hide this standard lightning message?

I have overridden the new button with the aura component and used the record edit form and handling error In the controller, but I don't want to show this error to the user.

enter image description here

Best Answer

You need to remove the <lightning:messages /> from the lightning:recordEditForm to remove the standard lightning message. Use the onerror attribute to handle the error.

Example

Markup

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <lightning:recordEditForm recordId="0035j00000MpvTxAAJ" objectApiName="Contact" onerror="{!c.handleError}">
        <lightning:messages />
        <lightning:outputField fieldName="AccountId" />
        <lightning:inputField fieldName="FirstName" />
        <lightning:inputField fieldName="LastName" />
        <lightning:inputField fieldName="Email" />
        <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="update" label="Update" />
    </lightning:recordEditForm>
</aura:component>

Controller

({
    handleError: function (component, event, helper) {
        //Get the error
        var error = event.getParams();
        console.log("Error : " + JSON.stringify(error));
        //Get the error message
        var errorMessage = event.getParam("message");
        console.log("Error Message : " + errorMessage);
    }   
})