From 2070e58e3e38ed71549268b59bbc56e810b321dc Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 7 Jan 2016 09:22:17 -0600 Subject: [PATCH] fix(inputs): fix form onChange/onTouch --- ionic/components/checkbox/checkbox.ts | 17 +++++++++++--- ionic/components/radio/radio.ts | 26 ++++++++++++++++++--- ionic/components/toggle/toggle.ts | 33 ++++++++++++++++++--------- 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/ionic/components/checkbox/checkbox.ts b/ionic/components/checkbox/checkbox.ts index 52c97f7fe3..23edccb730 100644 --- a/ionic/components/checkbox/checkbox.ts +++ b/ionic/components/checkbox/checkbox.ts @@ -55,9 +55,6 @@ export class Checkbox { ) { _form.register(this); - this.onChange = (_) => {}; - this.onTouched = (_) => {}; - if (ngControl) { ngControl.valueAccessor = this; } @@ -114,6 +111,20 @@ export class Checkbox { this.checked = value; } + /** + * @private + */ + onChange(val) { + // TODO: figure the whys and the becauses + } + + /** + * @private + */ + onTouched(val) { + // TODO: figure the whys and the becauses + } + /** * @private * Angular2 Forms API method called by the view (NgControl) to register the diff --git a/ionic/components/radio/radio.ts b/ionic/components/radio/radio.ts index 98f09afb80..d5da0cbc31 100644 --- a/ionic/components/radio/radio.ts +++ b/ionic/components/radio/radio.ts @@ -55,7 +55,9 @@ export class RadioButton { private _form: Form, private _renderer: Renderer, private _elementRef: ElementRef - ) {} + ) { + _form.register(this); + } /** * @private @@ -88,6 +90,13 @@ export class RadioButton { public set isChecked(isChecked) { this._renderer.setElementAttribute(this._elementRef, 'aria-checked', isChecked); } + + /** + * @private + */ + ngOnDestroy() { + this._form.deregister(this); + } } @@ -184,8 +193,19 @@ export class RadioGroup { } } - public onChange = (_:any) => {}; - public onTouched = () => {}; + /** + * @private + */ + onChange(val) { + // TODO: figure the whys and the becauses + } + + /** + * @private + */ + onTouched(val) { + // TODO: figure the whys and the becauses + } /** * @private diff --git a/ionic/components/toggle/toggle.ts b/ionic/components/toggle/toggle.ts index 2d1eb75b5a..fb99bc7091 100644 --- a/ionic/components/toggle/toggle.ts +++ b/ionic/components/toggle/toggle.ts @@ -91,9 +91,6 @@ export class Toggle { this.lastTouch = 0; this.mode = config.get('mode'); - this.onChange = (_) => {}; - this.onTouched = (_) => {}; - if (ngControl) { ngControl.valueAccessor = this; } @@ -164,13 +161,6 @@ export class Toggle { this.onChange(this._checked); } - /** - * @private - */ - writeValue(value) { - this.checked = value; - } - /** * @private */ @@ -209,6 +199,27 @@ export class Toggle { this.isActivated = false; } + /** + * @private + */ + writeValue(value) { + this.checked = value; + } + + /** + * @private + */ + onChange(val) { + // TODO: figure the whys and the becauses + } + + /** + * @private + */ + onTouched(val) { + // TODO: figure the whys and the becauses + } + /** * @private */ @@ -225,7 +236,7 @@ export class Toggle { ngOnDestroy() { this.removeMoveListener(); this.toggleEle = this.addMoveListener = this.removeMoveListener = null; - this.form.deregister(this); + this._form.deregister(this); } /**