diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eba6ad..eabc10d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ CHANGELOG ========= +## 3.0.3 + +- Fix issue when a single-value Selectivity input is reset to null throught the React API. + ## 3.0.2 - Fix #161: React API: Value should be re-set when the items change. diff --git a/src/selectivity.js b/src/selectivity.js index ceea176..a980601 100644 --- a/src/selectivity.js +++ b/src/selectivity.js @@ -187,6 +187,8 @@ extend(Selectivity.prototype, { var items = this.items; if (items) { return Selectivity.findNestedById(items, id); + } else if (id === null) { + return null; } else { return { id: id, text: '' + id }; } diff --git a/tests/unit/react/single.js b/tests/unit/react/single.js index e5edb20..4ea30ff 100644 --- a/tests/unit/react/single.js +++ b/tests/unit/react/single.js @@ -30,6 +30,47 @@ TestUtil.createReactTest( } ); +TestUtil.createReactTest( + 'react/single: test clear by setting null from outside', + ['inputs/single', 'dropdown', 'templates'], + { + allowClear: true, + async: true, + onChange: _.noop, + value: 1, + query: function(queryOptions) { + queryOptions.callback({ + results: [ + { id: 1, text: 'Amsterdam' }, + { id: 2, text: 'Antwerp' }, + { id: 3, text: 'Athens' } + ] + }); + } + }, + function(SelectivityReact, test, ref, container, $) { + test.plan(4); + + test.equal(ref.getValue(), 1); + + ReactDOM.render( + React.createElement(SelectivityReact, { + allowClear: true, + onChange: _.noop, + value: null + }), + container, + function() { + test.equal(ref.getData(), null); + test.equal(ref.getValue(), null); + + test.equal($('.selectivity-dropdown').length, 0); + test.end(); + } + ); + } +); + TestUtil.createReactTest( 'react/single: test initial data', ['inputs/single', 'templates'],