Skip to content

Commit fabc8db

Browse files
committed
Add value attribute to md-checkbox
1 parent 4ab6f30 commit fabc8db

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
[id]="inputId"
66
[required]="required"
77
[checked]="checked"
8+
[attr.checked]="checked"
9+
[attr.value]="value"
810
[disabled]="disabled"
911
[name]="name"
1012
[tabIndex]="tabindex"

src/lib/checkbox/checkbox.spec.ts

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

306+
it('should forward the value to input element', () => {
307+
testComponent.checkboxValue = 'basic_checkbox';
308+
fixture.detectChanges();
309+
310+
expect(inputElement.value).toBe('basic_checkbox');
311+
});
312+
306313
describe('color behaviour', () => {
307314
it('should apply class based on color attribute', () => {
308315
testComponent.checkboxColor = 'primary';
@@ -630,6 +637,7 @@ describe('MdCheckbox', () => {
630637
[indeterminate]="isIndeterminate"
631638
[disabled]="isDisabled"
632639
[color]="checkboxColor"
640+
[value]="checkboxValue"
633641
(change)="changeCount = changeCount + 1"
634642
(click)="onCheckboxClick($event)"
635643
(change)="onCheckboxChange($event)">
@@ -648,6 +656,7 @@ class SingleCheckbox {
648656
lastKeydownEvent: Event = null;
649657
changeCount: number = 0;
650658
checkboxColor: string = 'primary';
659+
checkboxValue: string = 'single_checkbox';
651660

652661
onCheckboxClick(event: Event) {}
653662
onCheckboxChange(event: MdCheckboxChange) {}

src/lib/checkbox/checkbox.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ export class MdCheckbox implements ControlValueAccessor {
147147
/** Event emitted when the checkbox's `checked` value changes. */
148148
@Output() change: EventEmitter<MdCheckboxChange> = new EventEmitter<MdCheckboxChange>();
149149

150+
/** The value attribute of the native input element */
151+
@Input() value: string ;
152+
150153
/** The native `<input type="checkbox"> element */
151154
@ViewChild('input') _inputElement: ElementRef;
152155

0 commit comments

Comments
 (0)