autocomplete
by gabriela b
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/flick/jquery-ui.css">
<script src="http://code.angularjs.org/1.0.0/angular-1.0.0.js"></script>
<div ng-app='MyModule'>
<div ng-controller='DefaultCtrl'>
<div ng-repeat='item in items'>
{{item}}
<input auto-complete ui-items="names" ng-model="selected">
<input id={{item.ref}} auto-complete ui-items="names2" test="item.ref" ng-model="selected2"> {{item.ref}}
</div>
</div>
</div>
<script type="text/javascript">
$("input,select").bind("keydown", function (event) {
if (event.which === 13) {
event.stopPropagation();
event.preventDefault();
$(':input:eq(' + ($(':input').index(this) + 1) + ')').focus();
}
});
</script>
JavaScript
function DefaultCtrl($scope) {
$scope.items = [
{'ref' : 'd',
'ref2' :'d'},
{'ref' : 'd2',
'ref2' :'d2'}
];
$scope.names = ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];
$scope.names2 = ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];
}
angular.module('MyModule', []).directive('autoComplete', function($timeout) {
return function(scope, iElement, iAttrs) {
iElement.autocomplete({
source: scope[iAttrs.uiItems],
select: function() {
$timeout(function() {
iElement.trigger('input');
//document.getElementById(iAttrs.inputId).focus();
alert(iAttrs);
var idInput = '#'+iAttrs.inputId;
$(idInput).focus();
}, 0);
}
});
};
});