Skip to content

Commit 709611f

Browse files
committed
Add value attribute to md-checkbox
1 parent 3b6cab0 commit 709611f

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

src/demo-app/checkbox/checkbox-demo.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<h1>md-checkbox: Basic Example</h1>
22
<form>
33
<md-checkbox [(ngModel)]="isChecked"
4-
name="cb"
4+
name="cb"
5+
value="basic_checkbox"
56
[color]="checkboxColor()"
67
(change)="isIndeterminate = false"
78
[indeterminate]="isIndeterminate"

src/lib/checkbox/checkbox.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[id]="inputId"
66
[required]="required"
77
[checked]="checked"
8+
[attr.value]="value"
89
[disabled]="disabled"
910
[name]="name"
1011
[tabIndex]="tabindex"

src/lib/checkbox/checkbox.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ describe('MdCheckbox', () => {
324324
expect(document.activeElement).toBe(inputElement);
325325
});
326326

327+
it('should forward the value to input element', () => {
328+
testComponent.checkboxValue = 'basic_checkbox';
329+
fixture.detectChanges();
330+
331+
expect(inputElement.value).toBe('basic_checkbox');
332+
});
333+
327334
describe('color behaviour', () => {
328335
it('should apply class based on color attribute', () => {
329336
testComponent.checkboxColor = 'primary';
@@ -675,6 +682,7 @@ describe('MdCheckbox', () => {
675682
[(indeterminate)]="isIndeterminate"
676683
[disabled]="isDisabled"
677684
[color]="checkboxColor"
685+
[value]="checkboxValue"
678686
(change)="changeCount = changeCount + 1"
679687
(click)="onCheckboxClick($event)"
680688
(change)="onCheckboxChange($event)">
@@ -693,6 +701,7 @@ class SingleCheckbox {
693701
lastKeydownEvent: Event = null;
694702
changeCount: number = 0;
695703
checkboxColor: string = 'primary';
704+
checkboxValue: string = 'single_checkbox';
696705

697706
onCheckboxClick(event: Event) {}
698707
onCheckboxChange(event: MdCheckboxChange) {}

src/lib/checkbox/checkbox.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ export class MdCheckbox implements ControlValueAccessor {
150150
/** Event emitted when the checkbox's `indeterminate` value changes. */
151151
@Output() indeterminateChange: EventEmitter<boolean> = new EventEmitter<boolean>();
152152

153+
/** The value attribute of the native input element */
154+
@Input() value: string ;
155+
153156
/** The native `<input type="checkbox"> element */
154157
@ViewChild('input') _inputElement: ElementRef;
155158

0 commit comments

Comments
 (0)