Skip to content

Instantly share code, notes, and snippets.

@timmyomahony
Created February 26, 2018 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmyomahony/238bd54d31d3983809440b7b3ffae7cb to your computer and use it in GitHub Desktop.
Save timmyomahony/238bd54d31d3983809440b7b3ffae7cb to your computer and use it in GitHub Desktop.
Example Angular form
$scope.submitForm = function(isValid) {
if ($scope.userForm.$valid) {
alert('Thank you for registering');
location.reload();
} else {
alert('Error registering');
}
}
<form name="userForm" ng-submit="submitForm(userForm.$valid)" novalidate>
<div class="form-group">
<label>Name</label>
<input type="text" id="name" name="name" ng-model="name" class="form-control" required>
<p ng-show="userForm.name.$invalid" class="help-block">Your name is required.</p>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" name="email" ng-model="email" class="form-control" required>
<p ng-show="userForm.email.$invalid" class="help-block">Your email is required.</p>
</div>
<input type="submit" class="btn btn-primary" value="Submit" ng-disabled="userForm.$invalid">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment