forked from im4aLL/Angular-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18.form.validation.html
More file actions
147 lines (86 loc) · 2.8 KB
/
18.form.validation.html
File metadata and controls
147 lines (86 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Form</title>
<link rel="stylesheet" href="src/doc.css">
</head>
<body>
<div ng-app="myApp">
<div ng-controller="formModule">
<form action="" name="registrationForm" novalidate ng-submit="submitForm(registrationForm.$valid)" class="custom">
<div class="row">
<label for="name">Name:</label>
<input type="text" id="name" ng-model="user.name" name="name" ng-pattern="[a-zA-Z]">
</div>
<div class="row"> <!--ng-class="{error: registrationForm.email.$invalid && !registrationForm.email.$pristine}"-->
<label for="email">Email address:</label>
<input type="email" name="email" id="email" ng-model="user.email" required>
<span ng-show="registrationForm.email.$invalid && !registrationForm.email.$pristine">Enter valid email address!</span>
</div>
<div class="row">
<label for="username">Username: </label>
<input type="text" id="username" name="username" ng-model="user.username" ng-minlength="3" ng-maxlength="8" required>
<span ng-show="registrationForm.username.$error.minlength">Username is too short.</span>
<span ng-show="registrationForm.username.$error.maxlength">Username is too long.</span>
</div>
<label for=""></label>
<button type="submit" ng-disabled="registrationForm.$invalid">SAVE</button>
</form>
</div>
</div>
<script src="src/angular.1.3.min.js"></script>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('formModule', ['$scope', function($scope) {
$scope.submitForm = function(isValid){
if( isValid ) alert('Form is valid!');
else alert('Form is invalid!');
return false;
};
}]);
</script>
<xmp>
<input type="text"
ng-model="{string}"
[name="{string}"]
[required]
[ng-required="{string}"]
[ng-minlength="{number}"]
[ng-maxlength="{number}"]
[ng-pattern="{string}"]
[ng-change="{string}"]>
</xmp>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<td>Property</td>
<td>Class</td>
<td>Description</td>
</tr>
</thead>
<tbody>
<tr>
<td class="success">$valid</td>
<td>ng-valid</td>
<td><em class="text-info">Boolean</em> Tells whether an item is currently valid based on the rules you placed.</td>
</tr>
<tr>
<td class="danger">$invalid</td>
<td>ng-invalid</td>
<td><em class="text-info">Boolean</em> Tells whether an item is currently invalid based on the rules you placed.</td>
</tr>
<tr>
<td class="active">$pristine</td>
<td>ng-pristine</td>
<td><em class="text-info">Boolean</em> True if the form/input <strong>has not</strong> been used yet.</td>
</tr>
<tr>
<td class="warning">$dirty</td>
<td>ng-dirty</td>
<td><em class="text-info">Boolean</em> True if the form/input <strong>has</strong> been used.</td>
</tr>
</tbody>
</table>
</body>
</html>