Skip to content

Commit

Permalink
fix(radio): add value reset with undefined (#2511)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashaqred authored Sep 17, 2020
1 parent 10b01fa commit 9ac12c7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/framework/theme/components/radio/radio-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,10 @@ export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, Contr

writeValue(value: any): void {
this.value = value;

if (typeof value !== 'undefined') {
this.updateValues();
}
}

protected updateAndSubscribeToRadios() {
this.updateValueFromCheckedOption();
this.updateNames();
this.updateValues();
this.updateDisabled();
Expand All @@ -204,9 +201,7 @@ export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, Contr
}

protected updateValues() {
if (typeof this.value !== 'undefined') {
this.updateAndMarkForCheckRadios((radio: NbRadioComponent) => radio.checked = radio.value === this.value);
}
this.updateAndMarkForCheckRadios((radio: NbRadioComponent) => radio.checked = radio.value === this.value);
}

protected updateDisabled() {
Expand Down Expand Up @@ -277,4 +272,12 @@ export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, Contr
});
}
}

protected updateValueFromCheckedOption() {
const checkedRadio = this.radios.find((radio) => radio.checked);
const isValueMissing = this.value === undefined || this.value === null;
if (checkedRadio && isValueMissing && checkedRadio.value !== this.value) {
this.value = checkedRadio.value;
}
}
}

0 comments on commit 9ac12c7

Please sign in to comment.