emposha/FCBKcomplete — Issue #110: onselect option position in addItem
Author: ilmarks
Created: 2012-01-06 18:17:23+00:00
State: open

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

```javascript
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 = $('');
var li = $('
').prepend(txt).append(aclose);

var _item = $('
'+xssDisplay(title)+'
');
if (options.onselect) {
if(funCall(options.onselect, _item) === false) {
$("#" + elemid + "_annoninput").remove();
element.change();
addInput(focusme);
clear_feed(1);
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:

```javascript
$(selector).fcbkcomplete({
onselect: function(item){
if(item._value == 'true'){
return true;
} else {
return false;
}
}
});
```