1
0
Fork 0
forked from 0x2620/oxjs

autocomplete, continued

This commit is contained in:
Rolux 2010-02-18 20:41:14 +05:30
commit fa04216352
2 changed files with 15 additions and 24 deletions

View file

@ -1564,7 +1564,6 @@ requires
},
size: self.options.size
});
self.value = "",
that.bindEvent("click_" + self.menuId, onClick);
that.bindEvent("deselect_" + self.menuId, onDeselect);
that.bindEvent("select_" + self.menuId, onSelect);
@ -1575,18 +1574,22 @@ requires
});
}
function autocomplete(items) {
var selected = -1;
if (items.length) {
items = $.map(items, function(title) {
items = $.map(items, function(title, position) {
if (that.val().toLowerCase() == title.toLowerCase()) {
selected = position;
}
return {
id: title.toLowerCase(), // fixme: need function to do lowercase, underscores etc?
title: title
};
});
self.menu.options({
items: items
items: items,
selected: selected
}).showMenu();
} else {
Ox.print("hiding")
self.menu.hideMenu();
}
}
@ -1615,21 +1618,12 @@ requires
}
function keypress(event) {
setTimeout(function() {
var val = that.val();
if (self.options.autocomplete && val != self.options.value) {
self.options.value = val;
if (val === "") {
self.menu.hideMenu();
} else {
self.options.autocomplete(val, autocomplete);
}
var value = that.val();
if (self.options.autocomplete && value != self.value) {
self.value = value;
self.options.autocomplete(self.value, autocomplete);
}
}, 50);
/*
if (event.keyCode == 38 || event.keyCode == 40) {
return false;
}
*/
}
function onClick(event, data) {
Ox.print("onClick", data)
@ -1637,14 +1631,11 @@ requires
self.menu.hideMenu();
}
function onDeselect(event, data) {
that.val(self.value);
//that.val(self.value);
}
function onSelect(event, data) {
self.value = that.val().substr(0, selection()[0]);
var position = self.value.length;
that.val(data.title);
selection(position);
self.element.setSelectionRange(position, data.title.length);
//self.value = that.val();
//that.val(data.title);
}
function selection() {
var start, end;