Commit 82124d52ed8dc7328fa83bd18e07b9430e845572
1 parent
8455c40bb2
Exists in
master
buscador sin resultados hace focus
Showing
2 changed files
with
13 additions
and
3 deletions
Show diff stats
src/js/controller.js
| 1 | 1 | angular.module('focaModalProveedor') |
| 2 | 2 | .controller('focaModalProveedorCtrl', [ |
| 3 | + '$timeout', | |
| 3 | 4 | '$filter', |
| 4 | 5 | '$scope', |
| 5 | 6 | '$uibModalInstance', |
| 6 | 7 | 'focaModalProveedorService', |
| 7 | 8 | 'transportista', |
| 8 | - function ($filter, $scope, $uibModalInstance, focaModalProveedorService, transportista) { | |
| 9 | + function ($timeout, $filter, $scope, $uibModalInstance, | |
| 10 | + focaModalProveedorService, transportista) { | |
| 9 | 11 | |
| 10 | 12 | $scope.filters = ''; |
| 11 | 13 | $scope.primerBusqueda = false; |
| ... | ... | @@ -32,19 +34,26 @@ angular.module('focaModalProveedor') |
| 32 | 34 | } |
| 33 | 35 | $scope.primerBusqueda = true; |
| 34 | 36 | $scope.proveedores = res.data; |
| 35 | - $scope.search(); | |
| 37 | + $scope.search(true); | |
| 36 | 38 | primera(); |
| 37 | 39 | $scope.searchLoading = false; |
| 38 | 40 | }); |
| 39 | 41 | } |
| 40 | 42 | }; |
| 41 | 43 | |
| 42 | - $scope.search = function () { | |
| 44 | + $scope.search = function (pressed) { | |
| 43 | 45 | if($scope.primerBusqueda) { |
| 44 | 46 | $scope.filteredProveedores = $filter('filter')( |
| 45 | 47 | $scope.proveedores, {$: $scope.filters} |
| 46 | 48 | ); |
| 47 | 49 | |
| 50 | + if(pressed && $scope.filteredProveedores.length === 0){ | |
| 51 | + $timeout(function() { | |
| 52 | + angular.element('#search')[0].focus(); | |
| 53 | + $scope.filters = ''; | |
| 54 | + }); | |
| 55 | + } | |
| 56 | + | |
| 48 | 57 | $scope.lastPage = Math.ceil( |
| 49 | 58 | $scope.filteredProveedores.length / $scope.numPerPage |
| 50 | 59 | ); |