Skip to content

Commit

Permalink
form validation added
Browse files Browse the repository at this point in the history
  • Loading branch information
enchained committed May 23, 2014
1 parent e2067cd commit 7eab548
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
12 changes: 7 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@
<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>

</head>
<body>
<body ng-controller="SearchController as search">
<div class="container">
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<form class="navbar-form navbar-default text-center" role="search">
<form name="searchForm" class="navbar-form navbar-default text-center" role="search" ng-submit="search.newSearch()" novalidate>
<div class="container-fluid">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search on Flickr">
<input name="keywords" type="text" class="form-control" placeholder="Search on Flickr" ng-model="search.keywords" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</div>
</form>
</div>
</div>

<div id="main" ng-controller="SearchController as search">
<div id="error" class="alert alert-danger" ng-hide="!(search.submitted)" ng-show="search.submitted && searchForm.keywords.$error.required">
Please, enter the search keywords.
</div>
<div id="main">
<div class="thumbnail picture" ng-repeat="product in search.products | offset: search.currentPage* search.itemsPerPage | limitTo: search.itemsPerPage">
<a href="{{product.flickr}}">
<img ng-src="{{product.img}}" alt="{{product.title}}">
Expand Down
19 changes: 16 additions & 3 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


(function() {
var app = angular.module('flickr-search', []);
var app = angular.module('flickr-search', [ ]);
var pictures = [
{
title: 'Photo Walk Blue Hour at the Trump Tower',
Expand Down Expand Up @@ -163,11 +163,24 @@
};
});

app.controller('SearchController', function(){
app.controller('SearchController', ['$http', function($http){
var search = this;

this.keywords = "";
this.submitted = false;
this.products = pictures;
this.itemsPerPage = 12;
this.currentPage = 0;

this.newSearch = function() {
this.submitted = true;
if (this.keywords) {
alert(this.keywords);
this.submitted = false;
}

};

this.range = function() {
var rangeSize = 5;
var ret = [];
Expand Down Expand Up @@ -213,7 +226,7 @@
this.currentPage = n;
};

});
}]);



Expand Down

0 comments on commit 7eab548

Please sign in to comment.