diff --git a/src/components/radio/Radio.js b/src/components/radio/Radio.js index 51c37fd6b5..122cd9f629 100644 --- a/src/components/radio/Radio.js +++ b/src/components/radio/Radio.js @@ -407,7 +407,9 @@ export default class RadioComponent extends ListComponent { return value; } - if (!isNaN(parseFloat(value)) && isFinite(value)) { + const isEquivalent = value.toString() === Number(value).toString(); + + if (!isNaN(parseFloat(value)) && isFinite(value) && isEquivalent) { value = +value; } if (value === 'true') { diff --git a/src/components/radio/Radio.unit.js b/src/components/radio/Radio.unit.js index 1562950a26..aa6a77427f 100644 --- a/src/components/radio/Radio.unit.js +++ b/src/components/radio/Radio.unit.js @@ -13,7 +13,8 @@ import { comp6, comp7, comp8, - comp9 + comp9, + comp10 } from './fixtures'; describe('Radio Component', () => { @@ -113,6 +114,23 @@ describe('Radio Component', () => { }); }); + it('Should set correct data for 0s values', (done) => { + Harness.testCreate(RadioComponent, comp10).then((component) => { + component.setValue('01'); + component.redraw(); + + setTimeout(()=>{ + assert.equal(component._data.radio, '01'); + component.setValue(1); + component.redraw(); + setTimeout(()=>{ + assert.equal(component._data.radio, 1); + done(); + }, 200); + }, 200); + }); + }); + it('Span should have correct text label', () => { return Harness.testCreate(RadioComponent, comp1).then((component) => { component.element.querySelectorAll('input').forEach((input) => { diff --git a/src/components/radio/fixtures/comp10.js b/src/components/radio/fixtures/comp10.js new file mode 100644 index 0000000000..8ff3642242 --- /dev/null +++ b/src/components/radio/fixtures/comp10.js @@ -0,0 +1,21 @@ +export default { + 'label': 'Radio', + 'optionsLabelPosition': 'right', + 'inline': false, + 'tableView': false, + 'values': [ + { + 'label': '01', + 'value': '01', + 'shortcut': '' + }, + { + 'label': '1', + 'value': '1', + 'shortcut': '' + } + ], + 'key': 'radio', + 'type': 'radio', + 'input': true +}; diff --git a/src/components/radio/fixtures/index.js b/src/components/radio/fixtures/index.js index 7af2ced9f3..9db3870977 100644 --- a/src/components/radio/fixtures/index.js +++ b/src/components/radio/fixtures/index.js @@ -7,4 +7,5 @@ import comp6 from './comp6'; import comp7 from './comp7'; import comp8 from './comp8'; import comp9 from './comp9'; -export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, comp9 }; +import comp10 from './comp10'; +export { comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, comp9, comp10 };