fix(text-input): fix floating labels by getting the value of the ngControl if it exists

Added some test cases for this to the floating labels example. Closes
#710
This commit is contained in:
Brandy Carney
2015-12-10 15:21:01 -05:00
parent 59c7aab15f
commit b6fc63aaba
3 changed files with 20 additions and 6 deletions

View File

@ -4,4 +4,12 @@ import {App} from 'ionic/ionic';
@App({ @App({
templateUrl: 'main.html' templateUrl: 'main.html'
}) })
class E2EApp {} class E2EApp {
constructor() {
this.myValues = {
value1: 'Dynamic Input',
value2: 'Dynamic Textarea'
};
}
}

View File

@ -8,10 +8,11 @@
<ion-input floating-label> <ion-input floating-label>
<ion-label>Floating Label 1</ion-label> <ion-label>Floating Label 1</ion-label>
<input type="text"> <input [(ng-model)]='myValues.value1' type="text">
</ion-input> </ion-input>
Value: {{ myValues.value1 }}
<ion-input floating-label class="input-has-value"> <ion-input floating-label>
<ion-label>Floating Label 2</ion-label> <ion-label>Floating Label 2</ion-label>
<input value="Has Value" type="text"> <input value="Has Value" type="text">
</ion-input> </ion-input>
@ -23,8 +24,9 @@
<ion-input floating-label> <ion-input floating-label>
<ion-label primary>Floating Label 4</ion-label> <ion-label primary>Floating Label 4</ion-label>
<textarea></textarea> <textarea [(ng-model)]='myValues.value2'></textarea>
</ion-input> </ion-input>
Value: {{ myValues.value2 }}
<ion-input floating-label> <ion-input floating-label>
<ion-label secondary>Floating Label 5</ion-label> <ion-label secondary>Floating Label 5</ion-label>

View File

@ -1,4 +1,4 @@
import {Component, Directive, Attribute, NgIf, forwardRef, Host, Optional, ElementRef, Renderer, Attribute} from 'angular2/angular2'; import {Component, Directive, Attribute, NgIf, forwardRef, Host, Optional, ElementRef, Renderer, Attribute, NgControl} from 'angular2/angular2';
import {NavController} from '../nav/nav-controller'; import {NavController} from '../nav/nav-controller';
import {Config} from '../../config/config'; import {Config} from '../../config/config';
@ -469,7 +469,8 @@ export class TextInputElement {
@Attribute('type') type: string, @Attribute('type') type: string,
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;
@ -484,9 +485,12 @@ export class TextInputElement {
renderer.setElementClass(elementRef, 'item-input', true); renderer.setElementClass(elementRef, 'item-input', true);
wrapper.registerInput(this); wrapper.registerInput(this);
} }
if (ngControl) this.ngControl = ngControl;
} }
ngOnInit() { ngOnInit() {
if (this.ngControl) this.value = this.ngControl.value;
this.wrapper && this.wrapper.hasValue(this.value); this.wrapper && this.wrapper.hasValue(this.value);
} }