Skip to content

Commit 6815e39

Browse files
authored
Merge pull request #125 from openmrs/RA-2106
RA-2106: UI Commons: Navigator: properly clear out values for a set o…
2 parents 39d8e72 + 181029a commit 6815e39

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

omod/src/main/webapp/resources/scripts/navigator/navigatorModels.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ FieldModel.prototype.resetValue = function() {
191191
if (selectedOption.length > 0) {
192192
selectedOption.removeAttr('selected');
193193
}
194-
// TODO expand to handle the case of a *set* of radio buttons being a single field?
195-
else if (this.element.attr('type') == 'radio' && this.element.is(':checked')) {
194+
else if (this.element.attr('type') == 'radio') {
196195
this.element.removeAttr('checked');
196+
this.element.siblings('input[type="radio"]').removeAttr('checked');
197197
}
198198
// handle checkbox
199199
else if (this.element.attr('type') == 'checkbox') {

omod/src/test/webapp/resources/scripts/navigatorModels.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,32 @@ describe("Test for simple form models", function() {
197197

198198
it("should reset the value of radio set field", function() {
199199
var fieldModel = new FieldModel();
200-
var element = jasmine.createSpyObj('element', ['removeAttr', 'removeClass', 'show', 'attr','is', 'find', 'val' ]);
200+
var element = jasmine.createSpyObj('element', ['removeAttr', 'removeClass', 'show', 'attr', 'is', 'find', 'val']);
201201
fieldModel.element = element;
202202
element.find = jasmine.createSpy('find() spy').and.returnValue([]);
203203
element.attr = jasmine.createSpy('attr() spy').and.returnValue('radio');
204-
element.is = jasmine.createSpy('is() spy').and.returnValue(true);
204+
var siblings = jasmine.createSpyObj('siblings', ['removeAttr']);
205+
element.siblings = jasmine.createSpy('siblings() spy').and.returnValue(siblings);
205206

206207
fieldModel.resetValue();
207208
expect(element.removeAttr).toHaveBeenCalledWith("checked");
209+
expect(element.siblings).toHaveBeenCalledWith('input[type="radio"]');
210+
expect(siblings.removeAttr).toHaveBeenCalledWith("checked");
211+
})
212+
213+
it("should reset checked on all sibling radio buttons in a radio set with multiple options", function() {
214+
var fieldModel = new FieldModel();
215+
var firstRadio = jasmine.createSpyObj('firstRadio', ['removeAttr', 'removeClass', 'show', 'attr', 'is', 'find', 'val']);
216+
fieldModel.element = firstRadio;
217+
firstRadio.find = jasmine.createSpy('find() spy').and.returnValue([]);
218+
firstRadio.attr = jasmine.createSpy('attr() spy').and.returnValue('radio');
219+
var otherRadios = jasmine.createSpyObj('otherRadios', ['removeAttr']);
220+
firstRadio.siblings = jasmine.createSpy('siblings() spy').and.returnValue(otherRadios);
221+
222+
fieldModel.resetValue();
223+
expect(firstRadio.removeAttr).toHaveBeenCalledWith("checked");
224+
expect(firstRadio.siblings).toHaveBeenCalledWith('input[type="radio"]');
225+
expect(otherRadios.removeAttr).toHaveBeenCalledWith("checked");
208226
})
209227

210228
});

0 commit comments

Comments
 (0)