Create Multi Select Combobox / picklist in Lightning Salesforce

Multi Select Combobox lightning component is easy to create and works for both single select and multi select.

Lightning comes with many pre-built components that are easy to use but still many components are missing by date. One of them is the multi-select Combobox/picklist component. We will create this within a single component without using any child component or event. You can find the complete source code in this post.

Multi Select Combobox component Features:

  • Single component
  • Options attribute to pass List
  • Option to switch between Single Select and Multi Select.
  • Separate attributes for single and multi select to get selected values.
  • search functionality to filter options
  • Option to set the minimum character to start searching
  • Ability to set the label of combobox
  • combobox disable functionality

Demo GIF:

Single Select Combobox:

Multi Select Combobox Lightning

 

Multi Select Combobox:

Multi Select Picklist Lightning

Requirement:

Step-1: Create the MultiSelectCombobox Component

For creating a new lightning component navigate to Developer Console > File > New > Lightning Component

Enter Name & Description and click Submit. Now component markup file will open y default. In the right sidebar, click on Controller, Helper, and Style to create those files too.

Lightning Bundle

Now since all the files are created, we will write markup for our component. I have used standard (Salesforce Lightning Design System) SLDS here for styling.

Markup for MultiSelectCombobox.cmp

Now open the controller file MultiSelectComboboxController.js and paste the below code.

Open the helper file MultiSelectComboboxHelper.js and paste the below code.

Finally paste the CSS in MultiSelectCombobox.css file.

Step-2: Now we will call the component.

For Single Select:

multi select picklist lightning

For Multi Select:

Finally, our component is ready to use. Now while calling this component, you need to pass the options list and attribute in which selected value will be stored. You can also set the additional attributes and switch between single and multi select component.

 

How to pass the data (Option list format):

Data should be passed as Object List in the form of label and value.

Eg: [{‘label’: ‘University of Texas’, ‘value’:’UTT112′}]

 

To disable a value in the list:

To disable a particular element in the options list, simply add ‘disabled’: true in that element object.

 

selected value in multi select combobox

multi select picklist dropdown

Also, Check:

To create a single-select custom lookup, check out: Custom Lookup Lightning Component

To create a Multi Select Lookup component, check out: Multi Select Lookup Lightning

For any queries or suggestions regarding this post, comment below:
Cheers … 🙂

Leave a Reply

avatar
  Subscribe  
Notify of