Advertisement
Guest User

Untitled

a guest
May 4th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. import {App, Platform} from 'ionic-angular';
  2. import {StatusBar} from 'ionic-native';
  3. import {HomePage} from './pages/home/home';
  4.  
  5. import { FORM_DIRECTIVES, FormBuilder, ControlGroup,Control, Validators, AbstractControl } from 'angular2/common';
  6. import {LandingmenuPage} from './pages/landingmenu/landingmenu';
  7. import {FormPage} from './pages/validatelogin/validatelogin';
  8.  
  9.  
  10. @App({
  11. template: '<ion-nav id="nav" [root]="rootPage"></ion-nav>',
  12. config: {} // http://ionicframework.com/docs/v2/api/config/Config/
  13. })
  14. export class MyApp {
  15. rootPage: any = FormPage;
  16.  
  17. constructor(platform: Platform) {
  18. platform.ready().then(() => {
  19. // Okay, so the platform is ready and our plugins are available.
  20. // Here you can do any higher level native things you might need.
  21. StatusBar.styleDefault();
  22. });
  23. }
  24. }
  25.  
  26. <ion-navbar *navbar>
  27. <ion-title>
  28. Authorization
  29. </ion-title>
  30. </ion-navbar>
  31.  
  32. <ion-content class="home" padding>
  33. <form [ngFormModel]="authForm" >
  34. <ion-item [class.error]="!username.valid && username.touched">
  35. <ion-label floating>Username</ion-label>
  36. <ion-input type="text" value="" [ngFormControl]="username"></ion-input>
  37. </ion-item>
  38. <div *ngIf="username.hasError('required') && username.touched"
  39. class="error-box">* Username is required!</div>
  40. <div *ngIf="username.hasError('minlength') && username.touched"
  41. class="error-box">* Minimum username length is 8!</div>
  42. <div *ngIf="username.hasError('checkFirstCharacterValidator') && username.touched"
  43. class="error-box">* Username cant't start with number!</div>
  44. <ion-item floating-label [class.error]="!password.valid && password.touched">
  45. <ion-label floating>Password</ion-label>
  46. <ion-input type="text" value="" [ngFormControl]="password" ></ion-input>
  47. </ion-item>
  48. <div *ngIf="password.hasError('required') && password.touched"
  49. class="error-box">* Password is required</div>
  50. <div *ngIf="password.hasError('minlength') && password.touched"
  51. class="error-box">* Minimum password length is 8!</div>
  52. <div *ngIf="password.hasError('checkFirstCharacterValidator') && password.touched"
  53. class="error-box">* Password cant't start with number!</div>
  54. <br/><br/>
  55. <button type="submit" class="custom-button" [disabled]="!authForm.valid" block>Submit</button>
  56. </form>
  57. </ion-content>
  58.  
  59. import { Page } from 'ionic-angular';
  60.  
  61. import { FORM_DIRECTIVES, FormBuilder, ControlGroup,Control, Validators, AbstractControl } from 'angular2/common';
  62.  
  63.  
  64. @Page({
  65. templateUrl: 'build/pages/form/form.html',
  66. directives: [FORM_DIRECTIVES]
  67. })
  68.  
  69. export class FormPage {
  70.  
  71. authForm: ControlGroup;
  72. username: AbstractControl;
  73. password: AbstractControl;
  74.  
  75. constructor(fb: FormBuilder) {
  76. this.authForm = fb.group({
  77. 'username': ['', Validators.compose([Validators.required, Validators.minLength(8), this.checkFirstCharacterValidator])],
  78. 'password': ['', Validators.compose([Validators.required, Validators.minLength(8),this. checkFirstCharacterValidator])]
  79. });
  80.  
  81. this.username = this.authForm.controls['username'];
  82. this.password = this.authForm.controls['password'];
  83. }
  84.  
  85. onSubmit(value: string): void {
  86. if(this.authForm.valid) {
  87. console.log('Submitted value: ', value);
  88. }
  89. }
  90.  
  91. checkFirstCharacterValidator(control: Control): { [s: string]: boolean } {
  92. if (control.value.match(/^d/)) {
  93. return {checkFirstCharacterValidator: true};
  94. }
  95. }
  96. }
  97.  
  98. <!DOCTYPE html>
  99. <html lang="en" dir="ltr">
  100.  
  101. <head>
  102. <title>Ionic</title>
  103. <meta charset="UTF-8">
  104. <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  105. <meta name="format-detection" content="telephone=no">
  106. <meta name="msapplication-tap-highlight" content="no">
  107.  
  108. <link ios-href="build/css/app.ios.css" rel="stylesheet">
  109. <link md-href="build/css/app.md.css" rel="stylesheet">
  110. <link wp-href="build/css/app.wp.css" rel="stylesheet">
  111. </head>
  112.  
  113. <body>
  114. <!--<ion-app></ion-app>-->
  115. <ion-nav #content [root]="rootPage"></ion-nav>
  116.  
  117. <!-- cordova.js required for cordova apps -->
  118. <script src="cordova.js"></script>
  119. <!-- Polyfill needed for platforms without Promise and Collection support -->
  120. <script src="build/js/es6-shim.min.js"></script>
  121. <!-- Zone.js and Reflect-metadata -->
  122. <script src="build/js/angular2-polyfills.js"></script>
  123. <!-- the bundle which is built from the app's source code -->
  124. <script src="build/js/app.bundle.js"></script>
  125. </body>
  126.  
  127. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement