Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 KB | None | 0 0
  1. //======= components.ts ========////
  2. import { Component } from '@angular/core';
  3. // import { EqualValidator } from './equal-validator.directive';
  4.  
  5.  
  6. @Component({
  7. selector: 'app-root',
  8. templateUrl: './app.component.html',
  9. styleUrls: ['./app.component.css'],
  10. // directives: [EqualValidator]
  11. })
  12. export class AppComponent {
  13. error="";
  14. errors=[];
  15. flag=false;
  16. users=[];
  17. user={
  18. firstName:'',
  19. lastName:'',
  20. email:'',
  21. password:'',
  22. passwordConfirmation:'',
  23. streetAddress:'',
  24. unit:'',
  25. city:'',
  26. state:'',
  27. mood:''
  28. }
  29. onSubmit(){
  30. this.errors=[];
  31. if(this.user.password!=this.user.password){
  32. this.error="Password confirmation does not match password!"
  33. this.errors.push(this.error);
  34. return this.errors
  35. }else{
  36. this.users.push(this.user);
  37. console.log(this.users);
  38. this.flag=true;
  39. this.user={
  40. firstName:'',
  41. lastName:'',
  42. email:'',
  43. password:'',
  44. passwordConfirmation:'',
  45. streetAddress:'',
  46. unit:'',
  47. city:'',
  48. state:'',
  49. mood:''
  50. }
  51. this.flag=true;
  52. }
  53. }
  54. }
  55. // ===========component.html =============
  56.  
  57.  
  58. <div id="wrapper">
  59. <div id="head">
  60. <h1>Registration Form!</h1>
  61. <div class="alert alert-danger" *ngIf="flag==true">Thank you for registering with us {{users[users.length-1].firstName}}.We just sent you a confirmation email on {{users[users.length-1].email}},and we will send all mail to {{users[users.length-1].streetAddress}} {{users[users.length-1].city}}
  62. {{users[users.length-1].state}}!
  63. </div>
  64. </div>
  65. <div id="body">
  66. <h3>Account Information!</h3>
  67. <form (ngSubmit)="onSubmit()" #myForm="ngForm">
  68. <p>*First Name:<input type="text" name="firstName" required minlength="4" maxlength="24" pattern="[a-zA-Z][a-zA-Z ]+" [(ngModel)]="user.firstName" #firstName='ngModel'></p>
  69. <div *ngIf="firstName.invalid && (firstName.dirty || firstName.touched)" class="alert alert-danger">
  70.  
  71. <div *ngIf="firstName.errors.required">
  72. First Name is required.
  73. </div>
  74. <div *ngIf="firstName.errors.minlength">
  75. First Name must be at least 4 characters long.
  76. </div>
  77. <div *ngIf="firstName.errors.pattern">
  78. First Name should be letters only!
  79. </div>
  80.  
  81. </div>
  82. <p>*Last Name:<input type="text" name="lastName" required minlength="4" maxlength="24" pattern="[a-zA-Z][a-zA-Z ]+" [(ngModel)]="user.lastName" #lastName='ngModel'></p>
  83. <div *ngIf="lastName.invalid && (lastName.dirty || lastName.touched)" class="alert alert-danger">
  84.  
  85. <div *ngIf="lastName.errors.required">
  86. Last Name is required.
  87. </div>
  88. <div *ngIf="lastName.errors.minlength">
  89. Last Name must be at least 4 characters long.
  90. </div>
  91. <div *ngIf="lastName.errors.pattern">
  92. Last Name should be letters only!
  93. </div>
  94.  
  95. </div>
  96.  
  97. <p>*Email:<input type="text" name="email" required minlength="4" maxlength="24" pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" [(ngModel)]="user.email" #email='ngModel'></p>
  98. <div *ngIf="email.invalid && (email.dirty || email.touched)" class="alert alert-danger">
  99.  
  100. <div *ngIf="email.errors.required">
  101. Email is required.
  102. </div>
  103. <div *ngIf="email.errors.minlength">
  104. Email must be at least 4 characters long.
  105. </div>
  106. <div *ngIf="email.errors.pattern">
  107. Email is of invalid format!
  108. </div>
  109.  
  110. </div>
  111.  
  112. <p>*Password:<input type="text" name="password" required minlength="16" maxlength="24" [(ngModel)]="user.password" #password='ngModel'></p>
  113. <div *ngIf="password.invalid && (password.dirty || password.touched)" class="alert alert-danger">
  114.  
  115. <div *ngIf="password.errors.required">
  116. Password is required.
  117. </div>
  118. <div *ngIf="password.errors.minlength">
  119. Password must be at least 16 characters long.
  120. </div>
  121. </div>
  122.  
  123. <p>*Password-Confirmation:<input type="text" name="passwordConfirmation" equal="password" [(ngModel)]="user.passwordConfirmation" #passwordConfirmation='ngModel'></p>
  124. <div *ngIf="passwordConfirmation.invalid && (passwordConfirmation.dirty || passwordConfirmation.touched)" class="alert alert-danger">
  125.  
  126. <div *ngIf="passwordConfirmation.errors.equal">
  127. Does not match the password!
  128. </div>
  129. <div *ngIf="errors.length>0">{{errors[0]}} </div>
  130. </div>
  131.  
  132. <p>*Street:<input type="text" name="streetAddress" required minlength="4" maxlength="24" [(ngModel)]="user.streetAddress" #streetAddress='ngModel'></p>
  133. <div *ngIf="streetAddress.invalid && (streetAddress.dirty || streetAddress.touched)" class="alert alert-danger">
  134.  
  135. <div *ngIf="streetAddress.errors.required">
  136. Street address is required.
  137. </div>
  138. <div *ngIf="streetAddress.errors.minlength">
  139. Street address must be at least 4 characters long.
  140. </div>
  141. </div>
  142.  
  143. <p>Unit:<input type="text" name="unit" [(ngModel)]="user.unit" #unit='ngModel'></p>
  144.  
  145. <p>*City:<input type="text" name="city" required minlength="4" maxlength="24" [(ngModel)]="user.city" #city='ngModel'></p>
  146. <div *ngIf="city.invalid && (city.dirty || city.touched)" class="alert alert-danger">
  147.  
  148. <div *ngIf="city.errors.required">
  149. City is required.
  150. </div>
  151. <div *ngIf="city.errors.minlength">
  152. City must be at least 4 characters long.
  153. </div>
  154. </div>
  155.  
  156. <p>*State:<select required [(ngModel)]="user.state" #state='ngModel'>
  157. <option value="WA">WA</option>
  158. <option value="IL">IL</option>
  159. <option value="MT">MT</option>
  160. <option value="AZ">AZ</option>
  161. <option value="TX">TX</option>
  162. </select></p>
  163. <div *ngIf="state.invalid && (state.dirty || state.touched)" class="alert alert-danger">
  164.  
  165. <div *ngIf="state.errors.required">
  166. State is required.
  167. </div>
  168. </div>
  169.  
  170. <p>*I'am feeling lucky:<input type="radio" name="mood" value="Yes" required [(ngModel)]="user.mood" #mood='ngModel'>Yes<input type="radio" name="mood" value="No" required [(ngModel)]="user.mood" #mood='ngModel'>NO</p>
  171. <div *ngIf="mood.invalid && (mood.dirty || mood.touched)" class="alert alert-danger">
  172.  
  173. <div *ngIf="mood.errors.required">
  174. Mood is required.
  175. </div>
  176. </div>
  177. <p><input type="submit" value="Register" [disabled]="!myForm.form.valid"></p>
  178. </form>
  179. </div>
  180. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement