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

View file

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