allow limit for autocomplete menu length

This commit is contained in:
rolux 2011-05-20 08:19:55 +02:00
parent 28138cc446
commit 3087690d89
2 changed files with 26 additions and 18 deletions

View file

@ -69,6 +69,7 @@ Ox.Input = function(options, self) {
autocompleteReplaceCorrect: false,
autocompleteSelect: false,
autocompleteSelectHighlight: false,
autocompleteSelectMax: 0,
autocompleteSelectSubmit: false,
autovalidate: null,
changeOnKeypress: false,
@ -274,14 +275,15 @@ Ox.Input = function(options, self) {
Ox.print('autocomplete', oldValue, oldCursor)
if (self.options.value || self.options.autocompleteReplaceCorrect) {
if(Ox.isFunction(self.options.autocomplete)) {
if(self.options.key) {
self.options.autocomplete(self.options.key,
self.options.value,
autocompleteCallback)
if (Ox.isFunction(self.options.autocomplete)) {
if (self.options.key) {
self.options.autocomplete(
self.options.key, self.options.value, autocompleteCallback
);
} else {
self.options.autocomplete(self.options.value,
autocompleteCallback)
self.options.autocomplete(
self.options.value, autocompleteCallback
);
}
} else {
autocompleteCallback(autocompleteFunction(self.options.value));
@ -334,17 +336,22 @@ Ox.Input = function(options, self) {
self.oldCursor = cursor();
self.oldValue = self.options.value;
self.$autocompleteMenu.options({
items: $.map(values, function(v, i) {
if (value == v.toLowerCase()) {
selected = i;
items: Ox.map(values, function(v, i) {
var ret = null;
if (
!self.options.autocompleteSelectMax ||
i < self.options.autocompleteSelectMax
) {
if (value == v.toLowerCase()) {
selected = i;
}
ret = {
id: v.toLowerCase().replace(/ /g, '_'), // fixme: need function to do lowercase, underscores etc?
title: self.options.autocompleteSelectHighlight ?
Ox.highlight(v, value, 'OxHighlight') : v
};
}
return {
id: v.toLowerCase().replace(/ /g, '_'), // fixme: need function to do lowercase, underscores etc?
title: self.options.autocompleteSelectHighlight ? v.replace(
new RegExp('(' + value + ')', 'ig'),
'<span class="OxHighlight">$1</span>'
) : v
};
return ret;
}),
selected: selected
}).showMenu();
@ -404,7 +411,7 @@ Ox.Input = function(options, self) {
);
}
} else if (Ox.isRegExp(self.options.autovalidate)) {
autovalidateCallback(autovalidateFunction(self.options.value));
autovalidateCallback(autovalidateFunction(self.options.value));
} else {
autovalidateTypeFunction(self.options.type, self.options.value);
}

View file

@ -462,6 +462,7 @@ Ox.VideoEditor = function(options, self) {
autocomplete: self.words,
autocompleteSelect: true,
autocompleteSelectHighlight: true,
autocompleteSelectMax: 10,
autocompleteSelectSubmit: true,
changeOnKeypress: true,
placeholder: 'Find...',