jQuery transform select into picker option -


i'm trying solve bug (it works fine on chrome). that's script transform select picker option:

jquery.fn.select2optionpicker = function(options) {     return this.each(function() {             var $ = jquery;             var select = $(this);             var multiselect = select.attr('multiple');             select.hide();              var buttonshtml = $('<div class="d2s"></div>');             var selectindex = 0;             var addoptgroup = function(optgroup) {                     if (optgroup.attr('label')) {                             buttonshtml.append('<strong>' + optgroup.attr('label') + '</strong>');                     }                     var ulhtml = $('<ul>');                     optgroup.children('option').each(function() {                             var img_src = $(this).data('img-src');                             var color = $(this).data('color');                              var lihtml = $('<li></li>');                             if ($(this).attr('disabled') || select.attr('disabled')) {                                     lihtml.addclass('disabled');                                     lihtml.append('<span>' + $(this).html() + '</span>');                             } else {                                      if (color) {                                             lihtml.append('<a href="#" style="background-color:' + color + '" data-select-index="' + selectindex + '">&nbsp;</a>');                                     } else if (img_src) {                                             lihtml.append('<a href="#" data-select-index="' + selectindex + '"><img class="image_picker" src="' + img_src + '"></a>');                                     } else {                                             lihtml.append('<a href="#" data-select-index="' + selectindex + '">' + $(this).html() + '</a>');                                     }                             }                              // mark current selection "picked"                             if ((!options || !options.nodefault) && $(this).attr('selected')) {                                     lihtml.children('a, span').addclass('picked');                             }                             ulhtml.append(lihtml);                             selectindex++;                     });                     buttonshtml.append(ulhtml);             }              var optgroups = select.children('optgroup');             if (optgroups.length == 0) {                     addoptgroup(select);             } else {                     optgroups.each(function() {                             addoptgroup($(this));                     });             }              select.after(buttonshtml);              buttonshtml.find('a').click(function(e) {                     e.preventdefault();                     var clickedoption = $(select.find('option')[$(this).attr('data-select-index')]);                     if (multiselect) {                             if (clickedoption.attr('selected')) {                                     $(this).removeclass('picked');                                     clickedoption.removeattr('selected');                             } else {                                     $(this).addclass('picked');                                     clickedoption.attr('selected', 'selected');                             }                     } else {                             if ($(this).hasclass('picked')) {                                     //$(this).removeclass('picked');                                     //clickedoption.removeattr('selected');                             } else {                                     buttonshtml.find('a, span').removeclass('picked');                                     $(this).addclass('picked');                                     clickedoption.attr('selected', 'selected');                             }                     }                          select.trigger('change');                 });         }); };  $('.js-d2s').select2optionpicker();  $('#showdropdown').change(function() {         $('.js-d2s').toggle();  }); 

here can find in action:
http://goo.gl/0ggfkk

(this pen not mine, got same problem following plugin: http://www.jqueryscript.net/form/jquery-plugin-to-convert-select-list-to-a-option-picker.html)

i'm using plugin convert select option pickers, found bug can't solve. if show dropdowns can see it. if select room 2, room 3, etc dropdown update too, if click on room 2 again (a button clicked / option selected), value won't updated. briefly, unselected option can refresh value , pass right variable. think it?


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -