autocomplete, continued
This commit is contained in:
parent
f71f0ac5ee
commit
27cc14db36
|
@ -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;
|
||||
|
|
|
@ -341,7 +341,7 @@
|
|||
"New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota",
|
||||
"Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
|
||||
"South Carolina", "South Dakota", "Tennessee", "Texas", "Utah",
|
||||
"Vermont", "Virginia", "Washington", "West Virgina", "Wisconsin",
|
||||
"Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin",
|
||||
"Wyoming"
|
||||
];
|
||||
if (value === "") {
|
||||
|
|
Loading…
Reference in New Issue
Block a user