bhDropdownSelect implements a multi-column drop-down select
using Bootstrap v5.1.3 dialog and jQuery v3.6.0.
This v1.0.0 version implements a two-column grid in a fixed
size dialog.
There is still much to be done. For example, among others,
smart positioning is the first priority, currently it is just
assumed that there is optimal space available for this plugin
to look its best.
Let's look at how it works. Full example codes are also included in the above
GitHub repo.
jQuery plugin bhDropdownSelect usage Example 01.
“Select a Language” demonstrates default
behaviours.
Please note that option “theme” ( safe ) could be omitted as it
is the default theme.
Changing the button “Select a Language”
label text to bold programmatically to
demonstrate that this plugin is chainable: it behaves
correctly according to jQuery plugin guidelines.
The HTML for the button and the text field are listed below:
And the corresponding JavaScript codes:
“Select Your Tropical Fruit” demonstrates:
Using a different data list. That is, on the same page,
different instances of this plugin are able to operate
on different data lists.
Setting “theme” to “eyesore”
-- which is the second CSS that comes with this plugin.
HTML for “Select Your Tropical Fruit”:
JavaScript for “Select Your Tropical Fruit”:
“Click to Select” -- this last one demonstrates what happen
when “source” -- that is, the data list -- is set to null,
this is also the default setting for option “source”.
HTML for “Click to Select”:
JavaScript for “Click to Select”:
Libraries' Scripts and Data List Format
This plugin needs Bootstrap and jQuery. We must include the followings:
Please note the above is just one way of doing the inclusion. And also for
this plugin, I am not providing minified version of the source files. For
my project, I am just bundling them into the project's minified JS and
minified CSS.
Data lists, such as AVAILABLE_LANGUAGES
and TROPICAL_FRUITS as seen previously,
are arrays of objects. Each object has two string properties:
'code' and 'name'.
For example:
Theming
This plugin has two built-in themes: safe
and eyesore. safe
is basically the default colours provided by Bootstrap CSS.
eyesore
is my own colour scheme. I am horrible with colours, I name them like
that for attention catching.
Users can define their colour scheme, such as
example02 as seen in the
following next and final example.
jQuery plugin bhDropdownSelect usage Example 02.
This example demonstrates using user-defined theme: example02.
The CSS for example02 theme:
HTML:
JavaScript:
Some Further Notes
As mentioned before, this version of the plugin does not have
smart positioning, it is just assumed that there is enough
space to make it fully visible. I would like to address this
as the first priority in the next version.
The container dialog is fixed size, there are no options to set
the width nor the height.
Still related to positioning, while the dialog is opened, if we
scroll the screen up, it does not move with the element that it
is attached to.
I would also like to make the number of columns a configureable
option.
Another desirable option is to enable multiple selection, whereby
users can select multiple items, then hit ( a new button ) to
select and close the dialog.