-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab10.html
More file actions
203 lines (177 loc) · 7.9 KB
/
lab10.html
File metadata and controls
203 lines (177 loc) · 7.9 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!-- AngularJS Form
AngularJS is constantly updating the state of both the form and the input fields.
Input fields have the following states:
1. $untouched The field has not been touched yet
2. $touched The field has been touched
3. $pristine The field has not been modified yet
4. $dirty The field has been modified
5. $invalid The field content is not valid
6. $valid The field content is valid
They are all properties of the input field, and are either true or false.
Forms have the following states:
1. $pristine No fields have been modified yet
2. $dirty One or more have been modified
3. $invalid The form content is not valid
4. $valid The form content is valid
5. $submitted The form is submitted
-->
<!DOCTYPE html>
<html ng-app="mymodule">
<head>
<title> AngularJS Form</title>
<meta charset="utf-8" />
<link href="Content/bootstrap.css" rel="stylesheet" />
<script src="Scripts/angular.js"></script>
<script src="jsFiles/moduleslab9.js"></script>
<script>
ComApp.controller("employeeControl", function ($scope) {
$scope.Emp = {
fname: "Amit Kumar",
lname: "Mishra",
Add1: "Delhi",
Email: "amit.mishra@carltonleisue.com"
};
$scope.reset = function() {
this.Emp.fname = "Amit Kumar";
this.Emp.lname = "Mishra";
this.Emp.Add1 = "Basti";
this.Emp.Email = "amit.mishra@carltonleisue.com";
};
//$scope.reset();
});
</script>
</head>
<body>
<h3> AngularJS Form and Validation</h3>
<div ng-controller="employeeControl">
<form name="EmpForm" novalidate>
<table class="table-bordered table-hover">
<tr>
<td><span class="text text-info">First Name: </span></td>
<td>
<input type="text" name="empfname" value="" ng-model="Emp.fname" class="form-control" required />
<span class="text-danger" ng-show="EmpForm.empfname.$dirty && EmpForm.empfname.$invalid">
<span ng-show="EmpForm.empfname.$error.required">First Name is required.</span>
</span>
</td>
</tr>
<tr>
<td><span class="text text-info">Last Name: </span></td>
<td>
<input type="text" name="emplname" value="" ng-model="Emp.lname" class="form-control" required/>
<span class="text-danger" ng-show="EmpForm.emplname.$dirty && EmpForm.emplname.$invalid">
<span ng-show="EmpForm.emplname.$error.required">Last Name is required.</span>
</span>
</td>
</tr>
<tr>
<td><span class="text text-info">Address: </span></td>
<td>
<input type="text" name="empAddress" value="" ng-model="Emp.Add1" class="form-control" required/>
<span class="text-danger" ng-show="EmpForm.empAddress.$dirty && EmpForm.empAddress.$invalid">
<span ng-show="EmpForm.empAddress.$error.required">Please Insert Address.</span>
</span>
</td>
</tr>
<tr>
<td><span class="text text-info">Email id: </span></td>
<td>
<input class="form-control" name="empEmail" type="email" ng-model="Emp.Email" length="100" required>
<span class="text-danger" ng-show="EmpForm.empEmail.$dirty && EmpForm.empEmail.$invalid">
<span ng-show="EmpForm.empEmail.$error.required">Email is required.</span>
<span ng-show="EmpForm.empEmail.$error.email">Invalid email address.</span>
</span>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="btnSubmit" value="Submit" ng-click="submit();" class="btn btn-default" />
<input type="button" name="btnreset" value="Reset" ng-click="reset();" class="btn btn-primary" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
<!--<html>
<head>
<title>Angular JS Forms</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<style>
table, th, td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="mainApp" ng-controller="studentController">
<form name="studentForm" novalidate>
<table border="0">
<tr>
<td>Enter first name:</td>
<td>
<input name="firstname" type="text" ng-model="firstName" required>
<span style="color:red" ng-show="studentForm.firstname.$dirty && studentForm.firstname.$invalid">
<span ng-show="studentForm.firstname.$error.required">First Name is required.</span>
</span>
</td>
</tr>
<tr>
<td>Enter last name: </td>
<td>
<input name="lastname" type="text" ng-model="lastName" required>
<span style="color:red" ng-show="studentForm.lastname.$dirty && studentForm.lastname.$invalid">
<span ng-show="studentForm.lastname.$error.required">Last Name is required.</span>
</span>
</td>
</tr>
<tr>
<td>Email: </td>
<td>
<input name="email" type="email" ng-model="email" length="100" required>
<span style="color:red" ng-show="studentForm.email.$dirty && studentForm.email.$invalid">
<span ng-show="studentForm.email.$error.required">Email is required.</span>
<span ng-show="studentForm.email.$error.email">Invalid email address.</span>
</span>
</td>
</tr>
<tr>
<td>
<button ng-click="reset()">Reset</button>
</td>
<td>
<button ng-disabled="studentForm.firstname.$dirty &&
studentForm.firstname.$invalid || studentForm.lastname.$dirty &&
studentForm.lastname.$invalid || studentForm.email.$dirty &&
studentForm.email.$invalid" ng-click="submit()">
Submit
</button>
</td>
</tr>
</table>
</form>
</div>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('studentController', function($scope) {
$scope.reset = function(){
$scope.firstName = "Mahesh";
$scope.lastName = "Parashar";
$scope.email = "MaheshParashar@tutorialspoint.com";
}
$scope.reset();
});
</script>
</body>
</html>-->