Giter Club home page Giter Club logo

jquery.sumoselect's Introduction

jquery.sumoselect

jquery.sumoselect.js - A beautiful cross device Single/Multi Select jQuery Select plugin.

A jQuery plugin that progressively enhances an HTML Select Box into a Single/Multiple option dropdown list. The dropdown list can be fully customizable using simple css. It can adapt itself according to any device, keeping in mind that the User Experience is not broken.

View Live Demo Here

Documentaion Documentation Here

Latest stable : Download from here

CDNJS

The folks at CDNJS host a copy of the library. The CDN is updated after the release is made public, which means there is a delay between the publishing of a release and its availability on the CDN, so keep that in mind. Just use these links:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.sumoselect/3.1.6/sumoselect.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.sumoselect/3.1.6/jquery.sumoselect.min.js"></script>

Notable Features

  • Inline Search.

  • Optgroup support.

  • Single and Multi select option.

  • Fully customizable by simple css.

  • Supports almost all devices.

  • Intelligently Renders itself according to the devices.

  • Renders native Single/Multiple pop up on Android, ios, Windows and other devices.

  • Custom postback data format (Multiple select data can be passed either as csv or default select)

  • Selected, Disabled, and Placeholder Support

  • Easily extendable to allow developers to create new widgets

Requirements

jQuery 1.8.3+ (It is always recommended to use the latest version of jQuery)

Desktop Browser Support

IE8+, Firefox 4+, Chrome, Safari 4+, Opera 11+ (Other browsers may work, but I did not test on them)

Mobile/Tablet Browser Support

iOs 3+, Android 2.1+ , Windows Mobile (Other browsers may work, but I did not test on them)

Forking

If you find that you need a feature that SumoSelect does not currently support, either let me know via the SumoSelect issue tracker, or fork SumoSelect on Github and easily extend SumoSelect to create your own widget!

Usage

To just go with the default options simply do

$(document).ready(function () {
  $('.selectBox').SumoSelect();
});

To provide optional settings, simply pass a settings object to SumoSelect()

$(document).ready(function () {
  $('.selectBox').SumoSelect({
    placeholder: 'This is a placeholder',
    csvDispCount: 3
  });
});

You can also use data attributes to set options

<select class="selectBox" multiple data-max="2">

If you want an instance to the SumoSelect object to call handler methods

const select;
$(document).ready(function () {
  select = $('.selectBox').SumoSelect();
});

NOTE: SumoSelect returns an array of select elements if there are more than one in the matching selector.

You can also find the instance to the SumoSelect object by directly selecting your select element like

$('select.selectBox')[0].sumo. .....

You can perform all the operations on the underlying original select and then reload the UI by

$('select.selectBox')[0].sumo.reload();
You can bind your handlers to some sumoselect specific events eg.
$('select.selectBox').on('sumo:opened', function(sumo) {
  // Do stuff here
  console.log("Drop down opened", sumo)
});

Available events

  • sumo:opened
  • sumo:opening
  • sumo:closing
  • sumo:closed
  • sumo:initialized
  • sumo:unloaded

Settings

Below are the available settings:

  • placeholder (string) The palceholder text to be displayed in the rendered select widget (on priority basis). Maximum priority is given to native placeholder attribute in select tag i.e. - <select placeholder="this is a placeholder" /> - Then the option with disabled and selected attribute i.e. <option disabled selected value="foo" > - Last to to the given placeholder attribute in the settings.

  • csvDispCount (int) The number of items to be displayed in the widget seperated by a , after that the text will be warped as 3+ Selected. Set 0 for all the options.

  • captionFormat (string) Its the format in which you want to see the caption when more than csvDispCount items are selected. its default value is '{0} Selected' ( here {0} will be replaced by the seletion count )

  • captionFormatAllSelected (string) Format of caption text when all elements are selected. set null to use captionFormat. It will not work if there are disabled elements in select. default is '{0} all selected!'

  • floatWidth (int) Minimum screen width of device below which the options list is rendered in floating popup fashion.

  • forceCustomRendering (boolean) Force the custom modal ( Floating list ) on all devices below floatWidth resolution.

  • nativeOnDevice (Array[string]) The keywords to identify a mobile device from useragent string. The system default select list is rendered on the matched device.

  • outputAsCSV (boolean) true to POST data as csv ( false for default select )

  • csvSepChar (string) Seperation char if outputAsCSV is set to true

  • okCancelInMulti (boolean) Displays Ok Cancel buttons in desktop mode multiselect also.

  • isClickAwayOk (boolean) for okCancelInMulti=true. sets whether click outside will trigger Ok or Cancel (default is cancel).

  • triggerChangeCombined (boolean) In Multiselect mode whether to trigger change event on individual selection of each item or on combined selection ( pressing of OK or Cancel button ).

  • selectAll (boolean) To display select all check or not

  • search (boolean) To enable searching in sumoselect (default is false).

  • searchText (string) placeholder for search input.

  • searchFn (function) Custom search function. Following parameters will be passed along: haystack, needle, el

  • noMatch (string) placeholder to display if no itmes matches the search term (default 'No matches for "{0}"').

  • prefix (string) prefix to prepend the selected text (default is empty) eg. 'Hello'.

  • locale (array) change the text used in plugin (['OK', 'Cancel', 'Select All']). Note: don't break the sequence or skip items.

  • up (boolean) the direction in which to open the dropdown (default: false)

  • showTitle (boolean) set to false to prevent title (tooltip) from appearing (deafult true)

  • max (int) Maximum number of selected options (if multiple)

  • renderLi (function) Custom <li> item renderer

  • clearAll (boolean) Display "Clear all" in multiselect (deafult false)

  • closeAfterClearAll (boolean) Close dropdown after clicking on "Clear all" (deafult false)

The default settings are :

{
    placeholder: 'Select Here',
    csvDispCount: 3,
    captionFormat:'{0} Selected', 
    captionFormatAllSelected:'{0} all selected!',
    floatWidth: 400,
    forceCustomRendering: false,
    nativeOnDevice: ['Android', 'BlackBerry', 'iPhone', 'iPad', 'iPod', 'Opera Mini', 'IEMobile', 'Silk'],
    outputAsCSV: false,
    csvSepChar: ',',
    okCancelInMulti: false,
    isClickAwayOk: false,
    triggerChangeCombined: true,
    selectAll: false,
    search: false,
    searchText: 'Search...',
    searchFn: function (haystack, needle, el) {
      return haystack.toLowerCase().indexOf(needle.toLowerCase()) < 0;
    },
    noMatch: 'No matches for "{0}"',
    prefix: '',
    locale: ['OK', 'Cancel', 'Select All'],
    up: false,
    showTitle: true,
    max: null,
    renderLi: (li, originalOption) => li,
    clearAll: false,
    closeAfterClearAll: false
}

Furthur Documentation

License

Copyright (c) 2016 Hemant Negi Licensed under the MIT license.

jquery.sumoselect's People

Contributors

b2f avatar brokolja avatar bryant1410 avatar cakama3a avatar celiakessassi avatar cprater avatar danscrim avatar deepsourcebot avatar dhanendra-kumar avatar dimalusa avatar ericwooley avatar hemantnegi avatar hkutluay avatar josephmosby avatar ke-an avatar kwizzn avatar librehost avatar maxqnei avatar mbardelmeijer avatar mbosecke avatar mertasan avatar morzel85 avatar rochet2 avatar rricote avatar samuelyvon avatar te-deum avatar vesrah avatar yiannisdesp avatar yura-brd avatar zenoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.sumoselect's Issues

Using system checkboxes instead of <span><i>?

This is great! Just what I was looking for.

I was thinking of swapping out the [span][i] checkboxes in favour of [input] checkboxes to avoid loading external graphics. But before I spent time working on it, I thought I'd ask: was there a compatibility reason (or other reason) for choosing [span][i]? (e.g., [input] won't work on Android or something like that?)

Thanks!

To hide the select box once we lost focus

Team,

         I see an issue like, if I have dropdown and a button in page, Once after the selection in the multiselect dropdown, I need to click the button twice, as the focus of the dropdown still there on first click. How can we solve it.

sumoselect methods does not work on ipad (IOS 6.0)

Hi,

i have tested the Sumoselect methods like add, unselect item etc.. with an Ipad (Version 6). All the methods doesn't work.
The Problems i.e.: if you unselect an item with $("#test")[0].sumo.unSelectItem(0), the first item in the original select option is unselected correctly, but the Sumoselelect itself does not change. The item is still marked as selected. Sumoselect does not update its state.

Another problem: You cannot loop through items i.e:
$("#" + id + " option").each(function(i) {

$("#" + id)[0].sumo.unSelectItem(i);

    });

All these problems seems to be a I-Pad specific. I tested this issues with Safari Browser on my window machine. Everything works. Also with Chrome, Firefox and IE no problems.

Well. Next week I have to finish a bigger project and your sumoselect is a important part of it. Do you have planned your next release already?

It would be very nice, if you can check this issues & and the Issue I wrote you some days before.

Thanks for your answer
Jens

Sumoselect working slow in IE11

Sumoselect (multiselect) working fine in all browsers except IE11. Even it works fine in IE9 and IE10. There are 4,000 entries in multiselect. Why it is working slow in ie11? any solution?

Collision detection

When the selectbox is on the bottom of an element with overflow: hidden;, it gets cropped and some of the options are unreachable for the user. Could you provide some way of setting a container element, so that the select box opens above the input in case it would colide with the containers bottom?

Firing click events on disabled items

If option was disabled by default and enable programmatically it will have no click event:

if (opt.attr('disabled') || opt.parent('optgroup').attr('disabled'))
    li.addClass('disabled');
else
    O.onOptClick(li);

And if option was disabled programmatically it will still have click event.

Because createLi method calls only once during initialization for each option.

You may see the test here: http://jsfiddle.net/xp4kf9kx/2/

New Feature: the ability for users to add their own options

Really awesome plugin you have here @HemantNegi. One UI feature that I get a lot from clients is the ability for users to be able to create their own option if it's not pre-populated in the multiselect (think the "other" field in questionnaires).

I'll submit a pull request as soon as I have a bit of time to work on it, but wanted to find out if anyone else would find this helpful.

unload method of multiselect does not work

Hi Hemant,

your unload method has a big problem with multiselect fields. After unload the multiselect, the multiselect is useless. The Problem: the "name attribute" of the originell select get lost after unload. So, no saving of values etc....

Do you know a fix, workaround? Well, it is urgent...

Thanks & greets
Jens

disable element

Hi,
thanks so much for this tool. Very nice.

My problem is, that I have no chance to "redraw" or "update" or "destroy" the Sumo Selects. In many of my projects I have to disable some oder all options of a select element in dependency of other selects. Take for e.g: I have select "a" and a select "b". If user select an option in "a", select "b" should be disabled (or some options of "b").
Even if I manipulate the DOM, take out your wrapped Divs and write the select field into the DOM again (now with disabled options) and call this new select with $(selector).SumoSelect... nothing happens.

A hint would be great
Greetings
Jens

fix doc

 $('select.SlectBox')[0].sumo.reload();

should give access to the select box, but the .SlectBox css class is not added to the node.

Javascript breaks in isMobile function

Added "if (!jQuery.isFunction( settings.nativeOnDevice[i] ))" to keep a string function from being applied on an object. Strangely this only broke pages that utilized mediaelement.js. Otherwise worked just fine. So far only tested on a PC, no mobile.

Multiselect - onsubmit - no get or post value

Hi,
I am running into an issue with form submission for multiple select.

To recreate issue:

//select
name = my_select[]
multiple = multiple
class = SlectBox

//js
$('.SlectBox').SumoSelect({okCancelInMulti:true, selectAll:true });

//form
action = get

//user action
select only one item and submit the form

The single option is not reported on submission.
On multiple selection, the last item is not reported on submission.

css not compatible with https

Hello,

The provided css is not compliant with https domains. This is due to the background-image :

background-image: url('http://graphics8.nytimes.com/packages/flash/business/20100325-FinancialTuneUp/gfx/checkbox.png');

Moreover, this image does not seems to be that essential : the same effect could be resolved using borders.

JS error in IE8

Hi,

thanks for the great plugin. I have an issue in IE8, it throws this error in jquery.sumoselect.js (also in minified version):
Line: 424
Char: 21
Error: Expected ':'

Any ideas? Thanks.

Internet Explorer 11: Item selection doesn't work

When I use Internet Explorer 11 to use the Sumoselect control white multiple selection, I cannot select an item from the dropdown menu. When the page is loaded I click on dropdown button, the menu appears. When I click in the flyout menu the menu disappears whithout selecting any item.

Confusingly sometimes the clicked item gets selected when I open the menu and wait for a while before clicking an item.

The Javascript console doesn't show any messages like errors. In other browsers (tested with chrome, firefox and opera) the same page works fine. The problem also appears on your demo page with Internet Explorer 11.

image
image

Support for <optgroup>

I find myself needing to use <optgroup> to split an option into two sub options as so:

<select>
        <option value="#option1">Option 1</option>
        <option value="#option2">Option 2</option>
        <option value="#option3">Option 3</option>
        <optgroup label="Option 4">
            <option value="#option4.1">Option 4.1</option>
            <option value="#option4.2">Option 4.2</option>
        </optgroup>
        <option value="#option5">Option 5</option>
        <option value="#option6">Option 6</option>
        <option value="#option7">Option 7</option>
    </select>

Is this possible?

sumo.unSelectItem is not working

I am trying to unslelect particular item but it is not working.
like - $('#parameter')[0].sumo.unSelectItem(3);
while its working fine with 0 index

optgroup style

Hi Hemant,

is it be possible to have a style for "optgroup"? With or without multiselect!

Best job,
John.

One Request

Is it possible to have the drop down stay opened at a fixed height, like a listbox?

IE8 - two problem

I have two problem in IE8.
First is in line 306 - i was add 'toString()' before 'toLowerCase()' and now it's work.
second problem is in 'get' and 'set' - ie8 doesn't support getters and setters. I working on it.

CSS images loaded from NY Times?

The default CSS links images from (probably copyright protected?) external sources like 'http://graphics8.nytimes.com'. Also some sources are not https-links, which can lead to problems when used on a https domain.

Wouldn't it be possible to store those icons locally in a folder?

TypeError: settings.nativeOnDevice[i].toLowerCase is not a function

got this error when using jquery no-conflict with mootools
the problem is on line 310

this is because mootools implements its own methods and other stuff in js I think
one solution is to never use for-var-in loop, and use regular for loop instead
or other solution is to check with typeof == 'string' in for-var-in loop in this case

this is the console.log(settings.nativeOnDevice[i]); result from this loop:
Android
BlackBerry
iPhone
iPad
iPod
Opera Mini
IEMobile
Silk
function()
Array()
function(t, e)
function()
function()
function(t)
function(t)
function(t)
function(t, e)

happens like I said on line 310
if (ua.toLowerCase().indexOf(settings.nativeOnDevice[i].toLowerCase())

Custom color for each individual option

Is it possible to set a different text color for each option within a sumoselect control?

I tried the following but did not seem to take effect: (text color still black)

-  $("#sumoselectControl option")[aryOptionListIndex].style.color = "#FF00CC"

-  $.each(aryOptionList, function (key, value) {
            $('#sumoselectControl')
                .append($("<option style='color:#FF00CC;'></option>")
                .attr("value", value)
                .text(value))
        });

Any ideas?

Thanks!!
Steve

_cnbtn is called on outside click?

Nice plugin ๐Ÿ‘

Ran into an outside click issue with a multi-select, a select all, and no Ok / Cancel buttons. If the user clicked outside after making their selections, the selected options are cleared.

Traced it back to this line:
if (O.is_multi && settings.selectAll)O._cnbtn();

Why is the O._cnbtn() function called here? Removing that call fixes this issue. Otherwise, the user must actually click on the CaptionCont to save the selections - which will not be obvious. Most users simply slick outside of a select to dismiss it, not click on the select again (even with the Ok / Cancel)


Edit: On 2nd thought, maybe this should be made on option as I do see it being useful in both use cases

Thanks.

Dev branch request

Hello,

With many new pull requests coming, I think it would be good to have a dev branch where you can push new features, then we'll take the time to improve tests on this branch until merge can be safely done on master.

Placeholder not working

Placeholders do not seem to populate. I tried removing all other select boxes to see if that made a difference, but does not appear to affect it.

Here is my original code with 4 select boxes, only the last one seems to take effect (multiselect):
http://jsfiddle.net/pa7g8qwx/

And here is just a single example, placeholders do not appear to work on some of these elements for some reason...
http://jsfiddle.net/jf9u96ns/1/

I've tried determining what the difference between the select boxes are, but was unable to find anything that would indicate why this is happening.

Please advise!

Client side validation

Does the plugin not carry forward the required attribute from the html select or am I missing something. And that being the case, If we want to manually apply required attribute which element would it be? It is necessary for client side validation.

Selected Size problem

When using the control in the mode where the all of the items are shown, the selected item view port is not displayed properly, there is some clipping... see attached picture.
sumo

Impossible to select dynamically added element lists

I was trying to add dynamically some li elements in the $( '.optWrapper .options ') via json, but after i added the elements i cannot select the added elements.

Code:

function ricreate_dep(){
    $.getJSON('index.php?dispatch=chat/ricreate_departments',function(json){ 
        $.each(json, function(key, val) {
    $('#group_id').append('<option value='+ val.id +'>'+ val.name +'</option>');
    $('.optWrapper .options').append("<li data-val=" + val.id + "><span><i></i></span><label>" + val.name + "</label></li>");
        }) 
        });
}

I cannot use $('select.SlectBox')[0].sumo.add('india'); because the SumoSelect is initialized from another function which creates dynamically a td row.
This function is called inside an ajax call.
Hope it's clear, because it's a bit complicated :-))
So is it possibile to delegate the click events instead of direct clicking the "checkboxes" (<i></i>) ?

Thanks in advance

Plugin is not working with ui tabs correctly

Hello,
Your plugin is amazing but there is a bug. I am using with JQUERY UI tabs and when i click first tab everything is working well, until i am clicking second tab and regions are loading in the first tab. Should load to second tab.

screenshot from second tab
screenshot_3

screenshot from first tab
screenshot_4

thank you very much,

Error in ipad

I am getting the following error in ipad
Error :
TypeError: 'undefined' is not an object (evaluating 'O.E.find('option[value="'+li.attr("data-val")+'"]')[0].selected=li.hasClass("selected")')

When I select any option the error is
Unable to set value of the property 'selected': object is null or undefined

A few items..

I really like what you've done here, and here are a few things that I couldn't find, or hopefully you may add.

  1. I couldn't find a way to manipulate the underlying select and then have the sumo select refresh its state. This would be nice, but if the other things are done, it's not absolutely required. You already update the select when items are added, which greatly simplifies my adoption!
  2. How do you remove ALL of the items. In a select, you just set the options length to 0.
  3. How do you clear all of the checked items in a multiselect? I believe that in a select, you just set the selected index to -1, however sumo dies if I do that!
  4. How do you set the height of the dropdown if possible?

Great Control, Thanks!

outputAsCSV should default to false

Thanks for the work you've done in this - it looks great!

The only issue I have is that the default outputAsCSV value changes how the form submits data. It took me a while to work out why my form suddenly didn't work when I sumo'd it (and how to fix that). I had thought I was just changing the look and feel (as with similar widgets I've used for jQuery UI).

Would it not make more sense for a simple $().SumoSelect({}) to leave the form POST exactly the same as it was before the call? I would have thought most people using this would only be looking for browser-side changes.

Enhancement

I like this lite wieght plug in - I am running into a brick wall and hoping you might be able to help me out. I need to make cascading drop downs example (Genre:) once that is populated fill a second dropdown (Artists:) with json from a web service. I am new to writing plugins and have played around with your code but can't seem to figure it out. Any help would be appreciated.

Placeholder to only show when dropdown is disabled

Hi,

When I set jQuery("#test")[0].sumo.disable(); I want only the Placeholder then to display 'Please Select a County First'.

At the moment I have $("#test").SumoSelect({ placeholder: 'Please Select a County First'}); , but that placeholder is also shown if no checkboxes are ticked.

Thanks

isMobile method "for" issue

In my code I am working with extensions methods on Array prototype. And I have a issue with method "isMobile". The method has "for" that run on a collection "settings.nativeOnDevice" without checking if the collection has has own a property. Without the check the method throw exception when try to accept to extension method on the collection.
Could you please add validation to the method if the collection has own the property or to change it to regular for with index ?

Example:

isMobile: function () {
   var ua = navigator.userAgent || navigator.vendor || window.opera;
   for (var i in settings.nativeOnDevice)
        if (settings.nativeOnDevice.hasOwnProperty(i))
           if (ua.toLowerCase().indexOf(settings.nativeOnDevice[i].toLowerCase()) > 0)
               return settings.nativeOnDevice[i];
   return false
}

Thanks

Placeholder doesn't work.

Using 2.1.0. Placeholders aren't working at all.

$('.selectbox').SumoSelect({
     placeholder: 'Test Placeholder'
});

Is this not the correct way?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.