hidden
attribute, therefore if you don't want to have
placeholder in list of options, use it with your placeholder option.
<select name="basic" id="ex-basic">
<option value="" disabled hidden>Select value</option>
<option value="1">Nice</option>
<option value="2">Very nice</option>
<option value="3">Awesome</option>
<option value="4">Godlike</option>
</select>
Javascript
$('#ex-basic').picker();
multiple
attribute with select tag and then enable multiple selection.
<select name="basic" id="ex-multiselect" multiple>
<option value="1">Kind</option>
<option value="2">Easy-going</option>
<option value="3">Extroverts</option>
<option value="4">Introverts</option>
<option value="5">Ambitious</option>
<option value="6">Loud</option>
</select>
Javascript
$('#ex-multiselect').picker();
<select name="basic" id="ex-multiselect-limit" multiple>
<option value="1">Kind</option>
<option value="2">Easy-going</option>
<option value="3">Extroverts</option>
<option value="4">Introverts</option>
<option value="5">Ambitious</option>
<option value="6">Loud</option>
</select>
Javascript
$('#ex-multiselect-limit').picker({limit: 2});
<select name="basic" id="ex-search" multiple>
<option value="1">Shanghai</option>
<option value="2">Karachi</option>
<option value="3">Beijing</option>
<option value="4">Tianjin</option>
<option value="5">Istanbul</option>
<option value="6">Lagos</option>
<option value="7">Tokyo</option>
<option value="8">Guangzhou</option>
<option value="9">Mumbai</option>
<option value="10">Moscow</option>
<option value="11">Dhaka</option>
<option value="12">Cairo</option>
</select>
Javascript
$('#ex-search').picker({search : true});
select
attribute. This will work for either basic or multiple modes. set
method. More about Picker's API in Documentation section.
<select name="basic" id="ex-search" multiple>
<option value="1">Shanghai</option>
<option value="2" selected>Karachi</option>
<option value="3">Beijing</option>
<option value="4" selected="selected">Tianjin</option>
<option value="5">Istanbul</option>
<option value="6">Lagos</option>
<option value="7">Tokyo</option>
<option value="8">Guangzhou</option>
<option value="9">Mumbai</option>
<option value="10">Moscow</option>
<option value="11">Dhaka</option>
<option value="12">Cairo</option>
</select><br>
<button id="ex-data-trigger">Select Cairo city</button>
Javascript
$('#ex-data-multiple').picker();
$('#ex-data-trigger').click(function () {
$('#ex-data-multiple').picker('set', 12);
})
value
. To enable this
feature you just have to pass object where key is the desired option's and
the class you want to assign to desired element.<select name="basic" id="ex-search" multiple>
<option value="1">Shanghai</option>
<option value="2" selected>Karachi</option>
<option value="3">Beijing</option>
<option value="4" selected="selected">Tianjin</option>
<option value="5">Istanbul</option>
</select><br>
Javascript
var classes = {
2 : 'orange',
4 : 'blue',
5 : 'orange'
};
$('#ex-coloring').picker({coloring: classes});
select
element.
<select name="basic" id="ex-events" multiple>
<option value="1">Kind</option>
<option value="2">Easy-going</option>
<option value="3">Extroverts</option>
<option value="4">Introverts</option>
<option value="5">Ambitious</option>
<option value="6">Loud</option>
</select>
JavaScript
var $elem = $('#ex-events');
$elem.picker();
$elem.on('sp-change', function(){
alert('Great! Thanks for letting me know!');
});
css/picker.min.css
and js/picker.min.js
in to your project
structure.
<link rel="stylesheet" href="path/to/file/picker.min.css">
<script type="text/javascript" src="path/to/file/picker.min.js"></script>
head
tag following part,
of course with modifying the path to the files
<link rel="stylesheet" href="css/picker.css">
<script type="text/javascript" src="js/picker.js"></script>
Then only thing you need to do is initialize Picker!
<script type="text/javascript">
$(document).ready(function(){
$('#your-selector').picker();
});
</script>
autofocusScrollOffset
.
coloring
parameter.containerClass
parameter you can specify what class should be
added to whole Picker wrapping element. It is mostly to be used for specific styling purposes.
containerWidth
parameter you can set the width of whole container.
This comes handy especially in multiple-selection mode, when the selected options
could be outstretching the container and cause some layout problems.
limit
parameter. After reaching the limit, the dropdown will be
hidden and will be shown again only when user will remove some of the options.
$('.multiple-used-class').picker(); // Will work
$('.multiple-used-class').picker('set', 2); // Will work
$('.multiple-used-class').picker('get'); // Won't work
Created by Adam Uhlíř © 2016
Name of event | Description |
---|---|
sp-change | Triggered when some element is chosen (in single mode) or add/removed (in multiple mode). |
sp-open | Triggered when is the dropdown menu opened. |
sp-close | Triggered when is the dropdown menu closed. |