emposha / FCBKcomplete

Jquery facebook like(fancy) multi-select
http://www.emposha.com
383 stars 116 forks source link

onselect option position in addItem #110

Closed IlmLV closed 8 years ago

IlmLV commented 12 years ago

Hi, i am newbie here, i haved a little problem with "onselect", i needed control of adding new item from these function, i fixed these problem, by editing addItem, i hope in new versions it will be included

function addItem(title, value, preadded, locked, focusme) {
        if (!maxItems()) {
          return false;
        }
        var liclass = "bit-box" + (locked ? " locked": "");
        var id = randomId();
        var txt = document.createTextNode(xssDisplay(title));
        var aclose = $('<a class="closebutton" href="#"></a>');
        var li = $('<li class="'+liclass+'" rel="'+value+'" id="pt_'+id+'"></li>').prepend(txt).append(aclose);

        var _item = $('<option value="'+xssDisplay(value, 1)+'" id="opt_'+id+'" class="selected" selected="selected">'+xssDisplay(title)+'</option>');
      if (options.onselect) {
        if(funCall(options.onselect, _item) === false) return false;
      }

        holder.append(li);

        aclose.click( function() {
          removeItem($(this).parent("li"));
          return false;
        });
        if (!preadded) {
          $("#" + elemid + "_annoninput").remove();
          addInput(focusme);

          element.append(_item);

          element.change();
        }
        holder.children("li.bit-box.deleted").removeClass("deleted");
        clear_feed(1);
        return id;
      }

usage:

$(selector).fcbkcomplete({
    onselect: function(item){
        if(item._value == 'true'){
            return true;
        } else {
            return false;
        }
    }
});
IlmLV commented 12 years ago

oh, and its would be useful to add addonspace option P.S. space keycode = 32