From 34c71b2e7e2bc5a12ecd113907f1e6a4e20ab797 Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Tue, 23 Jun 2015 16:17:43 -0500 Subject: [PATCH] more checkbox wip --- ionic/components/checkbox/checkbox.js | 20 ++++++++++++------- ionic/components/checkbox/test/basic/index.js | 16 ++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ionic/components/checkbox/checkbox.js b/ionic/components/checkbox/checkbox.js index b4537d4628..fd33c3c932 100644 --- a/ionic/components/checkbox/checkbox.js +++ b/ionic/components/checkbox/checkbox.js @@ -1,4 +1,4 @@ -import {ElementRef, Renderer} from 'angular2/angular2'; +import {ElementRef, Renderer, EventEmitter, onChange} from 'angular2/angular2'; import {isPresent} from 'angular2/src/facade/lang'; import {setProperty} from 'angular2/src/forms/directives/shared' @@ -20,7 +20,6 @@ import {Icon} from '../icon/icon'; -
@@ -38,8 +37,11 @@ export class Checkbox { 'iconOff': 'ion-ios-circle-outline', 'iconOn': 'ion-ios-checkmark' }, + //events: ['change'], host: { '(^click)': 'onClick($event)', + //'(change)': 'onChange($event.checked)', + '(blur)': 'onTouched()', '[checked]': 'checked', '[attr.aria-checked]': 'checked', '[attr.aria-disabled]': 'disabled', @@ -53,7 +55,8 @@ export class Checkbox { '[class.ng-valid]': 'ngClassValid', '[class.ng-invalid]': 'ngClassInvalid' }, - appInjector: [ NgControl ] + appInjector: [ NgControl ], + //lifecycle: [onChange] } } @@ -66,6 +69,8 @@ export class Checkbox { this.renderer = renderer; this.elementRef = elementRef; this.ngControl.valueAccessor = this; + + //this.change = new EventEmitter("change"); } onInit() { @@ -79,13 +84,14 @@ export class Checkbox { writeValue(value) { // Convert it to a boolean this.checked = !!value; - setProperty(this.renderer, this.elementRef, "checked", value); } set checked(checked) { - this._checked = checked - this.ngControl.control.checked = checked; - //this.controlDirective._control().updateValue(this._checked); + this._checked = checked; + // doesn't trigger change/validation for control? + setProperty(this.renderer, this.elementRef, "checked", checked); + //this.ngControl.control.checked = checked; + //this.change.next(checked); } get checked() { return this._checked diff --git a/ionic/components/checkbox/test/basic/index.js b/ionic/components/checkbox/test/basic/index.js index e176eed8f9..7f76aa9ab7 100644 --- a/ionic/components/checkbox/test/basic/index.js +++ b/ionic/components/checkbox/test/basic/index.js @@ -12,7 +12,8 @@ import { NgControl, ControlValueAccessor, NgControlName, - NgFormModel + NgFormModel, + FormBuilder } from 'angular2/forms'; import {Checkbox, Content, List} from 'ionic/ionic'; //import {IONIC_DIRECTIVES} from 'ionic/ionic' @@ -59,18 +60,19 @@ class IonicApp { // grapeCtrl: ['', Validators.required], // cherryCtrl: ['', Validators.required] // }; - // + // // this.fruitsForm = fb.group(this.controls); + this.fruitsForm = new ControlGroup({ "appleCtrl": new Control("APPLE", isChecked), "bananaCtrl": new Control("BANANA", isChecked), "grapeCtrl": new Control("GRAPE", isChecked), "cherryCtrl": new Control("CHERRY", isChecked) }); - // this.appleCtrl = new Control("APPLE", isChecked); - // this.bananaCtrl = new Control("BANANA", isChecked); - // this.grapeCtrl = new Control("GRAPE", isChecked); - // this.cherryCtrl = new Control("CHERRY", isChecked); + this.appleCtrl = "appleCtrl"; + this.bananaCtrl = "bananaCtrl"; + this.grapeCtrl = "grapeCtrl"; + this.cherryCtrl = "cherryCtrl"; function isChecked(ctrl) { if (ctrl.checked) { @@ -81,7 +83,7 @@ class IonicApp { } } } - } + } doSubmit(event) { console.log('Submitting form', this.fruitsForm.value);