fix(text-input): fixed text input so it will work without ngControl. Updated tests.

closes #710
This commit is contained in:
Brandy Carney
2015-12-18 11:11:17 -05:00
parent cbfc925191
commit 9fe1b34c8f
3 changed files with 22 additions and 29 deletions

View File

@ -14,7 +14,10 @@ class E2EApp {
comments: ["", Validators.required] comments: ["", Validators.required]
}); });
this.login = {}; this.login = {
email: 'help@ionic.io',
username: 'admin'
};
this.user = { this.user = {
username: 'asdf', username: 'asdf',

View File

@ -7,33 +7,24 @@
<form [ngFormModel]="loginForm" #mf="ngForm" novalidate> <form [ngFormModel]="loginForm" #mf="ngForm" novalidate>
<ion-list> <ion-list>
<ion-input> <ion-input floating-label>
<ion-label>Email:</ion-label> <ion-label>Email</ion-label>
<input [(ngModel)]="login.email" ngControl="email" type="email" placeholder="Required" required> <input [(ngModel)]="login.email" ngControl="email" type="email" required>
<button clear item-right>
<icon mail></icon>
</button>
</ion-input> </ion-input>
<ion-input> <ion-input floating-label>
<ion-label>Username:</ion-label> <ion-label>Username</ion-label>
<input [(ngModel)]="login.username" ngControl="username" type="text" placeholder="Optional"> <input [(ngModel)]="login.username" ngControl="username" type="text">
<button clear item-right>
<icon person></icon>
</button>
</ion-input> </ion-input>
<ion-input> <ion-input floating-label>
<ion-label>Password:</ion-label> <ion-label>Password</ion-label>
<input [(ngModel)]="login.password" ngControl="password" type="password" placeholder="Required" required> <input [(ngModel)]="login.password" ngControl="password" type="password" required>
<button clear item-right>
<icon lock></icon>
</button>
</ion-input> </ion-input>
<ion-input> <ion-input floating-label>
<ion-label>Comments:</ion-label> <ion-label>Comments</ion-label>
<textarea [(ngModel)]="login.comments" ngControl="comments" placeholder="Required" required>Comment value</textarea> <textarea [(ngModel)]="login.comments" ngControl="comments" required>Comment value</textarea>
</ion-input> </ion-input>
<div padding-left padding-right> <div padding-left padding-right>

View File

@ -1,5 +1,5 @@
import {Component, Directive, Attribute, forwardRef, Host, Optional, ElementRef, Renderer} from 'angular2/core'; import {Component, Directive, Attribute, forwardRef, Host, Optional, ElementRef, Renderer} from 'angular2/core';
import {NgIf, NgControl} from 'angular2/common'; import {NgIf} from 'angular2/common';
import {NavController} from '../nav/nav-controller'; import {NavController} from '../nav/nav-controller';
import {Config} from '../../config/config'; import {Config} from '../../config/config';
@ -457,7 +457,7 @@ export class TextInput {
*/ */
@Directive({ @Directive({
selector: 'textarea,input[type=text],input[type=password],input[type=number],input[type=search],input[type=email],input[type=url],input[type=tel],input[type=date],input[type=datetime],input[type=datetime-local],input[type=week],input[type=time]', selector: 'textarea,input[type=text],input[type=password],input[type=number],input[type=search],input[type=email],input[type=url],input[type=tel],input[type=date],input[type=datetime],input[type=datetime-local],input[type=week],input[type=time]',
inputs: ['value'], inputs: ['value', 'ngModel'],
host: { host: {
'(focus)': 'focusChange(true)', '(focus)': 'focusChange(true)',
'(blur)': 'focusChange(false)', '(blur)': 'focusChange(false)',
@ -471,7 +471,6 @@ export class TextInputElement {
elementRef: ElementRef, elementRef: ElementRef,
renderer: Renderer, renderer: Renderer,
@Optional() wrapper: TextInput, @Optional() wrapper: TextInput,
@Optional() ngControl: NgControl
) { ) {
this.type = type; this.type = type;
this.elementRef = elementRef; this.elementRef = elementRef;
@ -487,13 +486,13 @@ export class TextInputElement {
wrapper.registerInput(this); wrapper.registerInput(this);
} }
if (ngControl) this.ngControl = ngControl;
} }
ngAfterContentChecked() { ngOnInit() {
if (this.ngControl) console.log("Value", this.ngControl.value); if (this.ngModel) console.log("Value", this.ngModel);
if (this.ngControl) this.value = this.ngControl.value; if (this.ngModel) this.value = this.ngModel;
this.wrapper && this.wrapper.hasValue(this.value); this.wrapper && this.wrapper.hasValue(this.value);
console.log(this.value);
} }
focusChange(changed) { focusChange(changed) {