Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't start autocompleting if search is empty string #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h1><span class="thin">AngularJS:</span> Allmighty-Autocomplete Demo</h1>
<div class="main">
<h2>Search for new released movies:</h2>
<autocomplete ng-model="result" attr-placeholder="type to search movies..." click-activation="true" data="movies" on-type="doSomething" on-select="doSomethingElse"></autocomplete>
<button ng-click="clearSearch()">Clear Search</button>
<br>
<div class="description">
This is a simple autocomplete directive for AngularJS, packaged in a Angular module. You can check out the source code or download it here:
Expand Down
4 changes: 4 additions & 0 deletions script/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ app.controller('MyCtrl', function($scope, MovieRetriever){
return $scope.movies;
}

$scope.clearSearch = function() {
$scope.result = '';
};

$scope.doSomething = function(typedthings){
console.log("Do something like reload data with this: " + typedthings );
$scope.newmovies = MovieRetriever.getmovies(typedthings);
Expand Down
2 changes: 1 addition & 1 deletion script/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ app.directive('autocomplete', function() {
return;
}

if(watching && typeof $scope.searchParam !== 'undefined' && $scope.searchParam !== null) {
if(watching && $scope.searchParam) {
$scope.completing = true;
$scope.searchFilter = $scope.searchParam;
$scope.selectedIndex = -1;
Expand Down
9 changes: 9 additions & 0 deletions style/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ a:hover{
transition: 0.1s all ease-in-out;
}

.main button {
padding: 8px 16px;
font-size: 1.2em;
background: #eee;
border: 1px solid #999;
color: #444;
margin: 20px;
}

body{
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
min-height:100%;
Expand Down