Skip to content

Commit

Permalink
Prevent entering an existing option in the "Other" dialog
Browse files Browse the repository at this point in the history
Closes #75
  • Loading branch information
stdavis committed May 11, 2018
1 parent 3069659 commit 0ab2215
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions _src/app/OtherOptionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ define([
// event: Event Object
console.log('app/OtherOptionHandler:onTxtChange', arguments);

this.submitBtn.disabled = !(this.codeTxt.value.length > 0);
const value = this.codeTxt.value.toUpperCase();
this.submitBtn.disabled = !value || !(value.length > 0) ||
this.existingOptions.map(v => v.toUpperCase()).includes(value);

if (event.key === 'Enter') {
if (!this.submitBtn.disabled && event.key === 'Enter') {
this.onSubmit();
}
},
Expand Down
13 changes: 12 additions & 1 deletion _src/app/tests/spec/SpecOtherOptionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ require([
widget = null;
};
var select;
var options = ['code1', 'code2', 'code3'];
const code1 = 'code1';
var options = [code1, 'code2', 'code3'];

beforeEach(function () {
select = domConstruct.create('select', {}, win.body());
Expand Down Expand Up @@ -57,5 +58,15 @@ require([
testWidget.onSubmit();
});
});

describe('onTxtChange', function () {
it('does not allow for an existing value to be submitted', function () {
testWidget.codeTxt.value = code1.toUpperCase();

testWidget.onTxtChange({});

expect(testWidget.submitBtn.disabled).toBe(true);
});
});
});
});

0 comments on commit 0ab2215

Please sign in to comment.