Created
May 12, 2015 17:46
-
-
Save timhobbs/b9a4d457ae935069c4d5 to your computer and use it in GitHub Desktop.
Basic angular form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="app"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>Demo</title> | |
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"> | |
<style> | |
body { font-family: Calibri } | |
.form-horizontal .checkbox label { | |
margin-left: 10px; | |
} | |
</style> | |
</head> | |
<body> | |
<div ng-controller="EmailCtrl" class="container"> | |
<h1>Sign-up Today</h1> | |
<form name="subscribe" novalidate ng-submit="submit()"> | |
<div class="form-horizontal"> | |
<div class="form-group" ng-class="{ 'has-error': subscribe.EmailAddress.$invalid && submitted }"> | |
<label for="EmailAddress" class="col-md-2 control-label"> | |
Email Address | |
</label> | |
<div class="col-md-10"> | |
<input type="text" class="form-control" name="EmailAddress" id="EmailAddress" ng-model="sub.EmailAddress" required /> | |
</div> | |
</p> | |
<div class="form-group" ng-class="{ 'has-error': !sub.List1 && !sub.List2 && !sub.List3 && submitted }"> | |
<label class="col-md-2 control-label"> | |
Choose List(s) | |
</label> | |
<div class="col-md-10"> | |
<div class="checkbox"> | |
<label> | |
<input type="checkbox" name="List1" ng-model="sub.List1" /> | |
List 1 | |
</label> | |
</div> | |
<div class="checkbox"> | |
<label> | |
<input type="checkbox" name="List2" ng-model="sub.List2" /> | |
List 2 | |
</label> | |
</div> | |
<div class="checkbox"> | |
<label> | |
<input type="checkbox" name="List3" ng-model="sub.List3" /> | |
List 3 | |
</label> | |
</div> | |
</div> | |
</div> | |
<div ng-show="!sub.List1 && !sub.List2 && !sub.List3 && submitted" class="alert alert-danger col-md-offset-2 col-md-10"> | |
You must select a list. | |
</div> | |
</div> | |
<div class="form-group"> | |
<div class="col-md-offset-2 col-md-10"> | |
<button type="submit" class="btn btn-default">Submit</button> | |
<button type="button" class="btn btn-danger" ng-show="submitted" ng-click="reset()">Reset</button> | |
</div> | |
</div> | |
</form> | |
</div> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script> | |
<script> | |
var app = angular.module("app", []) | |
.controller("EmailCtrl", function ($scope) { | |
$scope.reset = function () { | |
$scope.sub = {}; | |
$scope.submitted = false; | |
}; | |
$scope.submit = function () { | |
$scope.submitted = true; | |
console.info("sub", $scope.sub); | |
}; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment