diff --git a/src/components/radio/Radio.js b/src/components/radio/Radio.js index 636970b9e2..eaed8451d3 100644 --- a/src/components/radio/Radio.js +++ b/src/components/radio/Radio.js @@ -365,12 +365,13 @@ export default class RadioComponent extends ListComponent { .then((response) => { this.loading = false; this.setItems(response); - this.optionsLoaded = true; - this.redraw(); }) .catch((err) => { - this.optionsLoaded = true; this.handleLoadingError(err); + }) + .finally(() => { + this.optionsLoaded = true; + this.redraw(); }); } diff --git a/test/unit/Radio.unit.js b/test/unit/Radio.unit.js index bd12027bc8..a4fd032280 100644 --- a/test/unit/Radio.unit.js +++ b/test/unit/Radio.unit.js @@ -322,6 +322,27 @@ describe('Radio Component', () => { done(); }).catch(done); }); + + it('Should not show infinite loader for radio with URL data source if options loading failed', (done) => { + const form = _.cloneDeep(comp9); + const element = document.createElement('div'); + const originalMakeRequest = Formio.makeRequest; + + Formio.makeRequest = function() { + return new Promise((res, rej) => { + setTimeout(() => rej('loading error'), 200); + }); + }; + Formio.createForm(element, form).then(form => { + const radio = form.getComponent('radio'); + assert.equal(!!radio.element.querySelector('.loader'), true, 'Should show loader.') + setTimeout(()=>{ + assert.equal(!!radio.element.querySelector('.loader'), false, 'Should not show loader.') + Formio.makeRequest = originalMakeRequest; + done(); + }, 350); + }).catch(done); + }); }); describe('Radio Component', () => {