Skip to content

Commit

Permalink
fix(checkbox, input, radio, slide-toggle): implement setDisabledState…
Browse files Browse the repository at this point in the history
… from ControlValueAccessor

Implements the `setDisabledState` method from the `ControlValueAccessor` interface in all of the input-related components, in order to support disabling via reactive forms. Note that the `select` component is missing the implementation, however there's a pending PR for it already (angular#1667).

Fixes angular#1171.
  • Loading branch information
crisbeto committed Nov 6, 2016
1 parent a0d85d8 commit 8ee8c87
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ export class MdCheckbox implements ControlValueAccessor {
this.onTouched = fn;
}

/**
* Implemented as a part of ControlValueAccessor.
*/
setDisabledState(isDisabled: boolean) {
this.disabled = isDisabled;
}

private _transitionCheckState(newState: TransitionCheckState) {
let oldState = this._currentCheckState;
let renderer = this._renderer;
Expand Down
7 changes: 7 additions & 0 deletions src/lib/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
this._onTouchedCallback = fn;
}

/**
* Implemented as a part of ControlValueAccessor.
*/
setDisabledState(isDisabled: boolean) {
this.disabled = isDisabled;
}

/** TODO: internal */
ngAfterContentInit() {
this._validateConstraints();
Expand Down
7 changes: 7 additions & 0 deletions src/lib/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
registerOnTouched(fn: any) {
this.onTouched = fn;
}

/**
* Implemented as a part of ControlValueAccessor.
*/
setDisabledState(isDisabled: boolean) {
this.disabled = isDisabled;
}
}


Expand Down
7 changes: 7 additions & 0 deletions src/lib/slide-toggle/slide-toggle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export class MdSlideToggle implements AfterContentInit, ControlValueAccessor {
this.onTouched = fn;
}

/**
* Implemented as a part of ControlValueAccessor.
*/
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}

@Input()
get checked() {
return !!this._checked;
Expand Down

0 comments on commit 8ee8c87

Please sign in to comment.