function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sai teja 69sai teja 69 

custom Form validation with error message on below the field while using lightning-record-form in LWC?

I have designed one form using lightning record edit form and i need to perform some client side validations before submitting the from and show some errors. Is there any inbuilt functionality in LWC
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sai,

Greetings to you!

To enable automatic error handling, include the component lightning-messages.To customize the behavior of your form when it loads or when data is submitted, use the onload and onsubmit attributes to specify event handlers. Errors are automatically handled. To customize the behavior of the form when it encounters an error on submission or when data is submitted successfully, use the onerror and onsuccess attributes to specify event handlers.
 
<template>
            <lightning-messages></lightning-messages>
 
    <lightning-record-form record-id={recordId} object-api-name="Account" layout-type="Full"
     columns="2" mode="View"
        onsuccess={handleSuccess} onsubmit={handleSubmit}>
    </lightning-record-form>
</template>

Please refer to the below links which might help you further with the above requirement.

https://developer.salesforce.com/docs/component-library/bundle/lightning-record-form/documentation

https://rajvakati.com/2019/02/16/lightning-record-form/

https://salesforce.stackexchange.com/questions/255367/how-to-use-lightning-record-form-onerror-to-display-custom-error-message

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas