Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {App, Platform} from 'ionic-angular';
- import {StatusBar} from 'ionic-native';
- import {HomePage} from './pages/home/home';
- import { FORM_DIRECTIVES, FormBuilder, ControlGroup,Control, Validators, AbstractControl } from 'angular2/common';
- import {LandingmenuPage} from './pages/landingmenu/landingmenu';
- import {FormPage} from './pages/validatelogin/validatelogin';
- @App({
- template: '<ion-nav id="nav" [root]="rootPage"></ion-nav>',
- config: {} // http://ionicframework.com/docs/v2/api/config/Config/
- })
- export class MyApp {
- rootPage: any = FormPage;
- constructor(platform: Platform) {
- platform.ready().then(() => {
- // Okay, so the platform is ready and our plugins are available.
- // Here you can do any higher level native things you might need.
- StatusBar.styleDefault();
- });
- }
- }
- <ion-navbar *navbar>
- <ion-title>
- Authorization
- </ion-title>
- </ion-navbar>
- <ion-content class="home" padding>
- <form [ngFormModel]="authForm" >
- <ion-item [class.error]="!username.valid && username.touched">
- <ion-label floating>Username</ion-label>
- <ion-input type="text" value="" [ngFormControl]="username"></ion-input>
- </ion-item>
- <div *ngIf="username.hasError('required') && username.touched"
- class="error-box">* Username is required!</div>
- <div *ngIf="username.hasError('minlength') && username.touched"
- class="error-box">* Minimum username length is 8!</div>
- <div *ngIf="username.hasError('checkFirstCharacterValidator') && username.touched"
- class="error-box">* Username cant't start with number!</div>
- <ion-item floating-label [class.error]="!password.valid && password.touched">
- <ion-label floating>Password</ion-label>
- <ion-input type="text" value="" [ngFormControl]="password" ></ion-input>
- </ion-item>
- <div *ngIf="password.hasError('required') && password.touched"
- class="error-box">* Password is required</div>
- <div *ngIf="password.hasError('minlength') && password.touched"
- class="error-box">* Minimum password length is 8!</div>
- <div *ngIf="password.hasError('checkFirstCharacterValidator') && password.touched"
- class="error-box">* Password cant't start with number!</div>
- <br/><br/>
- <button type="submit" class="custom-button" [disabled]="!authForm.valid" block>Submit</button>
- </form>
- </ion-content>
- import { Page } from 'ionic-angular';
- import { FORM_DIRECTIVES, FormBuilder, ControlGroup,Control, Validators, AbstractControl } from 'angular2/common';
- @Page({
- templateUrl: 'build/pages/form/form.html',
- directives: [FORM_DIRECTIVES]
- })
- export class FormPage {
- authForm: ControlGroup;
- username: AbstractControl;
- password: AbstractControl;
- constructor(fb: FormBuilder) {
- this.authForm = fb.group({
- 'username': ['', Validators.compose([Validators.required, Validators.minLength(8), this.checkFirstCharacterValidator])],
- 'password': ['', Validators.compose([Validators.required, Validators.minLength(8),this. checkFirstCharacterValidator])]
- });
- this.username = this.authForm.controls['username'];
- this.password = this.authForm.controls['password'];
- }
- onSubmit(value: string): void {
- if(this.authForm.valid) {
- console.log('Submitted value: ', value);
- }
- }
- checkFirstCharacterValidator(control: Control): { [s: string]: boolean } {
- if (control.value.match(/^d/)) {
- return {checkFirstCharacterValidator: true};
- }
- }
- }
- <!DOCTYPE html>
- <html lang="en" dir="ltr">
- <head>
- <title>Ionic</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
- <meta name="format-detection" content="telephone=no">
- <meta name="msapplication-tap-highlight" content="no">
- <link ios-href="build/css/app.ios.css" rel="stylesheet">
- <link md-href="build/css/app.md.css" rel="stylesheet">
- <link wp-href="build/css/app.wp.css" rel="stylesheet">
- </head>
- <body>
- <!--<ion-app></ion-app>-->
- <ion-nav #content [root]="rootPage"></ion-nav>
- <!-- cordova.js required for cordova apps -->
- <script src="cordova.js"></script>
- <!-- Polyfill needed for platforms without Promise and Collection support -->
- <script src="build/js/es6-shim.min.js"></script>
- <!-- Zone.js and Reflect-metadata -->
- <script src="build/js/angular2-polyfills.js"></script>
- <!-- the bundle which is built from the app's source code -->
- <script src="build/js/app.bundle.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement