So today we are going to create Custom Lookup Component in Lightning. As we all know lookups are very important components in Salesforce. Salesforce provides inputfield to handle the Lookup component out of the box. But they come with there own set of limitations. So today I have created a Custom Lookup Component in Lightning. Which we can easily use with our existing apps or component and can easily add the lookup functionality in them.
I tried to keep this component as simple as possible. So I did not use any event to communicate data between components. Instead, we have used two-way binding to pass data between components. Also, we have not used any third party library and only SLDS is used. So it will work in Locker service and can pass security review as well.
So below is the complete code. As we are using a single component to display lookup and dropdown for the result. So we don’t need to pass data between multiple components. Because of this, we have reduced the code here. Also, we don’t need to maintain multiple components here.
Now, this component supports Dynamic Icon, Required attribute, Dynamic Label. So this component also supports prepopulate field values. So if you want to use this in existing edit page you can use that as well. We can also use this in Tables as well. As we have used standard binding to pass data so they will not conflict with each other. You can download complete code from Github repo as well.
We have upgraded the above component and made it Lightning Web Component compatible. You can check here.
Did you like this component or want to add any feature, report any bug. Just let me know in the comments section. Happy Programming 🙂