Creates a multiple selection where you can have multiple option boxes adding values into one destination box.
You can also change the behavior of the option boxes:
remove the options after selecting, or be able to add options multiple times to the destination box.
Published under the MIT-License.
It can look like this if you know how to style it right (Screenshot taken from feindura - Flat File CMS):
You need to call the jsMultipleSelect() class and add some HTML markup. Here is how:
Add mootools core and the jsMultipleSelect.js to your website.
The simplest way to use it is to just call
window.addEvent('domready',function(){ new jsMultipleSelect(); });
An have the right HTML in the page.
If you want to customize it you can use the follwing options:
window.addEvent('domready',function(){ new jsMultipleSelect({ highlightColor:'#cccccc', removeButton: new Element('a',{'html':'remove'}), removeButtonClass: 'remove' }); });
Options
Events
select will be fired on the destination box when an option is selected. The event function will get the following parameters:
remove will be fired on the destination box when an option is removed. The event function will get the following parameters:
parsed will be fired on the destination box when the predefined selections inside the destination box are parsed. (You have to add a Eventlistener to the destination box BEFORE you call the jsMultipleSelect class, otherwise you won't catch the event) The event function will get the following parameters:
You need at least one option box <ul> element with the class "jsMultipleSelect"
and one destination box <ul> element with the class "jsMultipleSelectDestination".
Each option li stores a reference to their clone and visa versa. Just call clone.retrieve('option') or option.retrieve('clone') and you get the li in the option boxes or the li in the destination box.
<ul class="jsMultipleSelect" data-name="myInputFieldName" data-type="duplicates" data-jsMultipleSelect="1"> <li class="filter"><input type="text" placeholder="Type here to filter"></li> <li class="jsMultipleSelectOption" data-value="myValue1">Value Name 1></li> <li class="jsMultipleSelectOption" data-value="myValue2">Value Name 2></li> <li class="jsMultipleSelectOption" data-value="myValue3" data-type="remove">Removeable Value Name 3></li> </ul>
The <ul> element Attributes
The <li> elements Attributes
To add a Filter add the follwoing li element to your option boxes: <li class="filter"><input type="text" placeholder="Type here to filter"></li>.
To customize, you can add what ever you want in the inner part of the <li> elements, like images and text elements. It will all be transfered to the destination box when the option is selected.
thistexthelpstomakealinbreakaftertheimage
<ul class="jsMultipleSelectDestination" data-jsMultipleSelect="1"> <li data-value="myValue1" data-name="myInputFieldName" data-number="1"></li> <li data-value="myValue1" data-name="myInputFieldName" data-number="2"></li> <li data-value="myValue2" data-name="myInputFieldName"></li> <li data-value="myValue3" data-name="myInputFieldName"></li> </ul>
The <ul> element Attributes
The <li> elements Attributes
The <li> option data
Selections
The destination box ul stores a reference to two arrays. The removedOptions and the selectedOptions array. You can retrieve them by calling $('anIdToMyDestinationBox').retrieve('selectedOptions'); etc.
Clear selection
You can place a <a href="#" class="clearJsMultipleSelect" data-jsMultipleSelect="1">Clear Selection</a> somewhere with the right data-jsMultipleSelect ID attribute, to clear the corresponding destination box.
If you're wrapping the above elements with a <form> element and send this form to a PHP site you get the following $_POST/$_GET array: (example)
Array ( ['myInputFieldName'] => Array ( [0] => 'myValue2' [1] => 'myValue3' ) )
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus