From f20ae8fd3fceee1e25a16aa8493d1e31999db8c0 Mon Sep 17 00:00:00 2001 From: Brandy Carney Date: Tue, 26 Jan 2016 21:06:12 -0500 Subject: [PATCH] fix(radio): allow radios to check even without values --- ionic/components/radio/radio-button.ts | 14 ++++++++------ ionic/components/radio/radio-group.ts | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ionic/components/radio/radio-button.ts b/ionic/components/radio/radio-button.ts index 12b54a5fc4..93724af3ee 100644 --- a/ionic/components/radio/radio-button.ts +++ b/ionic/components/radio/radio-button.ts @@ -1,7 +1,7 @@ import {Component, Optional, Input, Output, HostListener, EventEmitter} from 'angular2/core'; import {Form} from '../../util/form'; -import {isTrueProperty} from '../../util/util'; +import {isTrueProperty, isDefined} from '../../util/util'; import {Item} from '../item/item'; import {ListHeader} from '../list/list'; import {RadioGroup} from './radio-group'; @@ -69,13 +69,15 @@ export class RadioButton { this._item.setCssClass('item-radio', true); } + console.log(this.value); + if (_group) { _group.register(this); } } - toggle() { - this.checked = !this._checked; + check() { + this.checked = true; } @Input() @@ -105,7 +107,7 @@ export class RadioButton { * @private */ setChecked(val: boolean) { - this._checked = val; + this._checked = isTrueProperty(val); this._item && this._item.setCssClass('item-radio-checked', val); } @@ -114,10 +116,10 @@ export class RadioButton { */ @HostListener('click', ['$event']) private _click(ev) { - console.debug('radio, select', this.value); + console.debug('radio, select', this.id); ev.preventDefault(); ev.stopPropagation(); - this.toggle(); + this.check(); } /** diff --git a/ionic/components/radio/radio-group.ts b/ionic/components/radio/radio-group.ts index 4cf5a21964..a358a54702 100644 --- a/ionic/components/radio/radio-group.ts +++ b/ionic/components/radio/radio-group.ts @@ -87,7 +87,7 @@ export class RadioGroup { writeValue(value) { this.value = isDefined(value) ? value : ''; this._buttons.forEach(button => { - let isChecked = (button.value === this.value); + let isChecked = button.checked; button.setChecked(isChecked); if (isChecked) { this._renderer.setElementAttribute(this._elementRef.nativeElement, 'aria-activedescendant', button.id);