fix(inputs): fix form onChange/onTouch

This commit is contained in:
Adam Bradley
2016-01-07 09:22:17 -06:00
parent f74606dc1b
commit 2070e58e3e
3 changed files with 59 additions and 17 deletions

View File

@ -55,9 +55,6 @@ export class Checkbox {
) { ) {
_form.register(this); _form.register(this);
this.onChange = (_) => {};
this.onTouched = (_) => {};
if (ngControl) { if (ngControl) {
ngControl.valueAccessor = this; ngControl.valueAccessor = this;
} }
@ -114,6 +111,20 @@ export class Checkbox {
this.checked = 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 * @private
* Angular2 Forms API method called by the view (NgControl) to register the * Angular2 Forms API method called by the view (NgControl) to register the

View File

@ -55,7 +55,9 @@ export class RadioButton {
private _form: Form, private _form: Form,
private _renderer: Renderer, private _renderer: Renderer,
private _elementRef: ElementRef private _elementRef: ElementRef
) {} ) {
_form.register(this);
}
/** /**
* @private * @private
@ -88,6 +90,13 @@ export class RadioButton {
public set isChecked(isChecked) { public set isChecked(isChecked) {
this._renderer.setElementAttribute(this._elementRef, 'aria-checked', 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 * @private

View File

@ -91,9 +91,6 @@ export class Toggle {
this.lastTouch = 0; this.lastTouch = 0;
this.mode = config.get('mode'); this.mode = config.get('mode');
this.onChange = (_) => {};
this.onTouched = (_) => {};
if (ngControl) { if (ngControl) {
ngControl.valueAccessor = this; ngControl.valueAccessor = this;
} }
@ -164,13 +161,6 @@ export class Toggle {
this.onChange(this._checked); this.onChange(this._checked);
} }
/**
* @private
*/
writeValue(value) {
this.checked = value;
}
/** /**
* @private * @private
*/ */
@ -209,6 +199,27 @@ export class Toggle {
this.isActivated = false; 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 * @private
*/ */
@ -225,7 +236,7 @@ export class Toggle {
ngOnDestroy() { ngOnDestroy() {
this.removeMoveListener(); this.removeMoveListener();
this.toggleEle = this.addMoveListener = this.removeMoveListener = null; this.toggleEle = this.addMoveListener = this.removeMoveListener = null;
this.form.deregister(this); this._form.deregister(this);
} }
/** /**