I would like to know if I can set a handler function so that it will be invoked when errors occur while submitting a record-edit-form in LWC. By errors I mean, required field errors. 'onerror' event is not working.


From the documentation there is a custom event named error that is emited upon failure.


For including the error message just add lightning-messages immediately before or after the lightning-edit-form

You can also override and manually capture it .

In your submit button add an attribute onerror and call a method handleError

<lightning-button variant="brand" type="submit" name="save" label="Create Account" onerror={handleError}> </lightning-button>

have not tested it , try using the below

handleError(event) {
  • Hi Mohith, I am not getting any call back to handleError() function. Jan 23 '20 at 5:58

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.