Skip to content

Custom HTML select box based on twitter bootstrap components.

License

Notifications You must be signed in to change notification settings

mitris/boot-select

Repository files navigation

boot-select

Custom HTML select box based on twitter bootstrap components.

Installation

It's quite simple and will take few minutes :)

The next steps assume that you have already include jQuery and Bootstrap on your page.

Download and include boot-select.css and boot-select.js on your page:

<html>
  <head>
    ...
    <link rel="bootstrap.css">
    <link rel="boot-select.css">
    ...
  </head>
  <body>
    ...
    <select id="your-select">
      <!-- options -->
    </seelct>
    ...
    <script src="jquery.js"></script>
    <script src="bootstrap.js"></script>
    <script src="boot-select.js"></script>
  </body>
</html>
$(function() {
  $('#your-select').bootSelect(/* options */)
});

That's it :) Profit!

Optional

Simply include nanoScroller on your page and ugly browser scroll would replaced with nice scroll :)

Example with all supported options provided by default:

$('#your-select').bootSelect({
  enableClear: true,
  keyboardNavigation: true,
  placeholder: 'Выберите из списка',
  clearButton: '&times;',
  toggleButton: '<i class="icon-angle-down"></i>',
  onInit: function () {
    // your own logic here...
  },
  onChange: function () {
    // your own logic here...
  }
});

Options:

enableClear - Show clear button near caret icon.

keyboardNavigation - Enable esc return up and down keyboard buttons, when dropdown list is activated

placeholder - Placeholder text/html. Showing when nothing selected or <select> cleared.

clearButton - text/html for clear button

toggleButton - text/html for toggle button. By default it is one of Font-Awesome icon. You can change it to any Bootstrap icon.

onInit function - Called, when sets selection of selected default option.

onChange function - Called, when selected option was changed.

Public methods:

clear - Clear selected value, or if select not have empty option set selectedIndex to -1

select - Select value. Accepts one argument - value of option, native <option>, or <option> wrapped with jQuery

update - Use this, when you add/remove options on your select dynamically (for example, you manually add option via $('#your-select').append('<option value="new">New</option>) )

toggle - Toggle show/hide dropdown

show - Show dropdown. Known issue: doesn't work properly

hide - Hide dropdown

Usage of methods:

  $('#your-select').bootSelect('clear');
  ...
  $('#your-select').bootSelect('select', 'value');

Depends on:

@TODO

  • Support of <optgroup> tag

You can request any additional functionality with the [issue](You can request any additional functionality with the issue and if it will be useful, I'll try to implement it.) and if it will be useful, I'll try to implement it.

About

Custom HTML select box based on twitter bootstrap components.

Resources

License

Stars

Watchers

Forks

Packages

No packages published