Lightning, Lightning, Lightning… With each new day we found something interesting in Lightning. There are many new things coming in lightning that’s make us to try our hand on all of them. Previously if we need to create Edit or detail page we need to manually create them with all custom code and then we can use Lightning:recordEditForm or LightningDataService.
But that still take lots of code. But now we have lightning:recordForm, which enables usto quickly create forms to add, view, or update a record. Using this component to create record forms is easier than building forms manually with
Using a single line of code we can create full page layout.
<lightning:recordForm recordId="001XXXXXX" objectApiName="Account" layoutType="Full" mode="view" />
But what if we need to add some custom validation before creating record or need to check some detail or update some fields before saving the record then we can also customize this as well. Today we will take an example where we will use onsubmit to save the record and then redirect to record detail page.
Here for demo purpose I didn’t done much customization but you can make changes. Also don’t forget to stop the standard flow else it will create two records for you.
As this component is generic so you can use it with any object to quickly get the edit page or create new record.
Did you want to add anything or have any question, please let me know in comments section. Happy programming 🙂