Skip to content

Commit

Permalink
Add value attribute to md-checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao committed Jan 17, 2017
1 parent 4ab6f30 commit fabc8db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/demo-app/checkbox/checkbox-demo.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<h1>md-checkbox: Basic Example</h1>
<form>
<md-checkbox [(ngModel)]="isChecked"
name="cb"
name="cb"
value="basic_checkbox"
[color]="checkboxColor()"
(change)="isIndeterminate = false"
[indeterminate]="isIndeterminate"
Expand Down
2 changes: 2 additions & 0 deletions src/lib/checkbox/checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[id]="inputId"
[required]="required"
[checked]="checked"
[attr.checked]="checked"
[attr.value]="value"
[disabled]="disabled"
[name]="name"
[tabIndex]="tabindex"
Expand Down
9 changes: 9 additions & 0 deletions src/lib/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ describe('MdCheckbox', () => {
expect(document.activeElement).toBe(inputElement);
});

it('should forward the value to input element', () => {
testComponent.checkboxValue = 'basic_checkbox';
fixture.detectChanges();

expect(inputElement.value).toBe('basic_checkbox');
});

describe('color behaviour', () => {
it('should apply class based on color attribute', () => {
testComponent.checkboxColor = 'primary';
Expand Down Expand Up @@ -630,6 +637,7 @@ describe('MdCheckbox', () => {
[indeterminate]="isIndeterminate"
[disabled]="isDisabled"
[color]="checkboxColor"
[value]="checkboxValue"
(change)="changeCount = changeCount + 1"
(click)="onCheckboxClick($event)"
(change)="onCheckboxChange($event)">
Expand All @@ -648,6 +656,7 @@ class SingleCheckbox {
lastKeydownEvent: Event = null;
changeCount: number = 0;
checkboxColor: string = 'primary';
checkboxValue: string = 'single_checkbox';

onCheckboxClick(event: Event) {}
onCheckboxChange(event: MdCheckboxChange) {}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export class MdCheckbox implements ControlValueAccessor {
/** Event emitted when the checkbox's `checked` value changes. */
@Output() change: EventEmitter<MdCheckboxChange> = new EventEmitter<MdCheckboxChange>();

/** The value attribute of the native input element */
@Input() value: string ;

/** The native `<input type="checkbox"> element */
@ViewChild('input') _inputElement: ElementRef;

Expand Down

0 comments on commit fabc8db

Please sign in to comment.