Select Options
The Select Options API of Bootstrap-Nice-Select
Bootstrap Version
Because there are some changes in class names and layout between Bootstrap 4 and Bootstrap 5, bootstrap-nice-select needs to know the version of Bootstrap you are using. By default, bootstrap-nice-select automatically detects the version of Bootstrap. However, there are some instances where the version detection does not work properly (e.g. Bootstrap is being loaded asynchronously or there is a namespace collision). For now, bootstrap-nice-select does not default to using a specific Bootstrap formatting if version detection fails. Normally if the version detection fails, there is a problem on user side which should be fixed.
Default Settings
You can change the default settings for bootstrap-nice-select by modifying bootstrapNiceSelect.DEFAULTS
object as example:
animation
- Attribute:
data-animation
- Type:
Boolean
- Detail:
Set to
false
if you do not want to have animation effects for the API methodsshow()
andhide()
. - Default:
true
- Example: Animation
disabled
- Attribute:
disabled="disabled"
- Type:
String
- Detail:
You can disable the whole
<select>
component so you can not add or delete already selected<option>
tags. You can also disable single<option>
tags to add them and make them unremovable. Works withdata-search-data
- JSON format needs to be expanded withdisabled: true
as attribute for a singleitem
. Default isdisabled: false
and does not need to be added. - Default:
undefined
- Example: From HTML
init
- Attribute:
data-bs-toggle
- Type:
String
- Detail: Activate bootstrap-nice-select without writing JavaScript.
- Default:
'bootstrap-nice-select'
- Example: From HTML
icons
- Attribute:
icons
- Type:
Object
- Detail: Set own custom icons via Javascript for the placeholder icons.
- Default:
- Example: Icons
locale
- Attribute:
data-locale
- Type:
String
- Detail:
Sets the locale to use (i.e.
'de-DE'
). Locale files currently all inside file and do not need to be pre-loaded. If leftundefined
, an empty string or a locale which is not allowed, errors are thrown. - Default:
'en-US'
- Example: Locale
minimumInputLength
- Attribute:
data-minimum-input-length
- Type:
Number
- Detail:
Sets the minimum number of characters required to start a search. Default value of
0
will directly trigger a search on autofill popup search - Default:
0
- Example: Minimum Input Length
scrollable
on
- Attribute:
data-scrollable-on
- Type:
Boolean
- Detail:
Set
true
to enable virtual scroll to display a virtual, “infinite” list. Needsdata-scrollable-height
to be set to work. - Default:
false
- Example: Scrollable
height
- Attribute:
data-scrollable-height
- Type:
String
- Detail:
Set a valid CSS
height
to display a virtual, “infinite” list. Needsdata-scrollable-on
to be set to work. - Default:
undefined
- Example: Scrollable
searchData
- Attribute:
data-search-data
- Type:
String
|Function
- Detail: Used to load the select field data for adding new items. The function needs to return elements in a specific JSON format to work properly.
- Default:
undefined
- Example: Remote Data
tags
- Attribute:
data-tags
- Type:
Boolean
- Detail:
Set
true
to enable dynamic item creation on input search field with pressing “,”. The separators that should be used when tokenizing can be specified using thetokenSeparators
option. - Default:
false
- Example: Tagging
tagsCheck
- Attribute:
data-tags-check
- Type:
String
|Function
- Detail:
Used to add some logic to the select field to return a
Boolean
if an invalid value is entered. - Default:
undefined
- Example: Constraining Tag Creation
theme
- Attribute:
data-theme
- Type:
String
- Detail: Set an allowed theme:
- Default:
'font-awesome-6'
- Example: Theme
tokenSeparators
- Attribute:
data-token-separators
- Type:
Array
- Detail: The separators that should be used when tokenizing.
- Default:
[","]
- Example: Token Separators