Overriding default behavior when a record is saved in LDS within Lightning Web Components
We can use LDS tags that salesforce provides to interact with data as far as a single record is concerned.
But there might be a few scenarios where we would have to override the standard functionality and implement some custom functionality.
Let me give you an example, If I were to show a form with only a view fields in the form and then take care of pupulating the remaining fields from the controller file then I can do it by overriding the save functionality.
But how can I do it in the first place?
We need to implement onsubmit={handleSubmit}
attribute on the tag <ligthning-record-edit-form>
.
That is going to invoke the method handleSubmit method in the controller rather than saving the method straight.
In the method handleSubmit
we need to stop the event propagation, map the remaining fields to it's values and finally submit the form.
Let me show you a snippet!
Hope this was helpful!