1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
function enableAutoComplete(/*jquery object*/ input, /*String*/ type) {
/**
* Enable autocomplete method.
* open and close methods are used for prevent bug when an item is
* selected above password input.
*/
input.autocomplete({
create : function(event, ui) {
/* Used because css was scoped with "autocompletion" class */
$('.ui-autocomplete').wrap('<div class="autocompletion"></div>');
},
open : function(event, ui) {
var passwordInput = $('#password-tag');
if (passwordInput) {
passwordInput.attr('disabled', 'disabled');
}
},
close : function(event, ui) {
var passwordInput = $('#password-tag');
if (passwordInput) {
passwordInput.removeAttr('disabled');
}
}
});
/* New source for autocompletion when keyup */
input.keyup(function(e) {
var userArray = new Array();
try {
var value = input.val();
var users;
if (value != '') {
users = NativeMethodProvider.getAutoCompletionData(value, type);
}
var usersObject = JSON.parse(users);
for (var key in usersObject) {
var value = usersObject[key];
userArray.push(value);
}
} catch(errback) {
...
}
input.autocomplete("option", "source", userArray);
});
}; |
Partager