fix(radio): set initial radio-group value

This commit is contained in:
Adam Bradley
2017-11-21 13:00:08 -06:00
parent 70fcc84364
commit 3ef39cbe8d
2 changed files with 16 additions and 3 deletions

View File

@ -87,9 +87,22 @@ export class RadioGroup implements ComponentDidLoad, RadioGroupInput {
this.radios.push(radio); this.radios.push(radio);
radio.name = this.name; radio.name = this.name;
if (radio.checked && !this.value) { if (this.value !== undefined && radio.value === this.value) {
// set the initial value from the check radio's value // this radio-group has a value and this
// radio equals the correct radio-group value
// so let's check this radio
radio.checked = true;
} else if (this.value === undefined && radio.checked) {
// this radio-group does not have a value
// but this radio is checked, so let's set the
// radio-group's value from the checked radio
this.value = radio.value; this.value = radio.value;
} else if (radio.checked) {
// if it doesn't match one of the above cases, but the
// radio is still checked, then we need to uncheck it
radio.checked = false;
} }
} }

View File

@ -21,7 +21,7 @@
<ion-list> <ion-list>
<ion-radio-group name="tannen" id="group"> <ion-radio-group name="tannen" id="group" value="biff">
<ion-list-header> <ion-list-header>
<ion-label>Luckiest Man On Earth</ion-label> <ion-label>Luckiest Man On Earth</ion-label>