From 8feb951bf5d5b8d6139ecb251aff60cd12516010 Mon Sep 17 00:00:00 2001 From: Brandy Carney Date: Wed, 25 Nov 2015 16:43:25 -0500 Subject: [PATCH] fix(radio): add ability to set ng-model on a radio group and check the corresponding radio button with that value added a test for ng-model with a radio. references #530 --- ionic/components/radio/radio.ts | 15 +++++++---- ionic/components/radio/test/basic/index.ts | 12 +++++++++ ionic/components/radio/test/basic/main.html | 30 ++++++++++++++++++--- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/ionic/components/radio/radio.ts b/ionic/components/radio/radio.ts index 7de459c3eb..f507bfd4ac 100644 --- a/ionic/components/radio/radio.ts +++ b/ionic/components/radio/radio.ts @@ -60,13 +60,13 @@ export class RadioGroup extends Ion { @Query(ListHeader) private headerQuery: QueryList ) { super(elementRef, config); - + this.ngControl = ngControl; this.id = ++radioGroupIds; this.radioIds = -1; this.onChange = (_) => {}; this.onTouched = (_) => {}; - if (ngControl) ngControl.valueAccessor = this; + if (ngControl) this.ngControl.valueAccessor = this; } /** @@ -91,6 +91,11 @@ export class RadioGroup extends Ion { radio.id = radio.id || ('radio-' + this.id + '-' + (++this.radioIds)); this.radios.push(radio); + console.log("Radio", radio.id, radio.value, radio.checked); + if (this.value == radio.value) { + radio.check(this.value); + } + if (radio.checked) { this.value = radio.value; this.activeId = radio.id; @@ -213,9 +218,9 @@ export class RadioButton extends Ion { /** * @private */ - click(ev) { - ev.preventDefault(); - ev.stopPropagation(); + click(event) { + event.preventDefault(); + event.stopPropagation(); this.check(); } diff --git a/ionic/components/radio/test/basic/index.ts b/ionic/components/radio/test/basic/index.ts index e5cf0835da..a14701f71b 100644 --- a/ionic/components/radio/test/basic/index.ts +++ b/ionic/components/radio/test/basic/index.ts @@ -22,6 +22,18 @@ class E2EApp { this.fruitsForm = new ControlGroup({ "fruits": this.fruits }); + + this.currenciesControl = new Control(""); + + this.currencyForm = new ControlGroup({ + "currenciesControl": this.currenciesControl + }); + + this.currencies = ['USD', 'EUR']; + this.selectedCurrency = 'EUR'; + + this.relationship = 'friends'; + } setApple() { diff --git a/ionic/components/radio/test/basic/main.html b/ionic/components/radio/test/basic/main.html index f4b09f1064..790e51ad86 100644 --- a/ionic/components/radio/test/basic/main.html +++ b/ionic/components/radio/test/basic/main.html @@ -32,15 +32,37 @@ - -

+

fruits.dirty: {{fruitsForm.controls.fruits.dirty}}
fruits.value: {{fruitsForm.controls.fruits.value}}
-

+
+ +
+ + + Currencies + + {{currency}} + +
+ +
+ currenciesControl.value: {{currencyForm.controls.currenciesControl.value}} +
+ + + Friends + Enemies + + +
+ relationship: {{relationship}} +