Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
Fix issue when a single-value Selectivity input is reset to null thro…
Browse files Browse the repository at this point in the history
…ught the React API.
  • Loading branch information
arendjr committed Dec 2, 2016
1 parent 6bdb140 commit 42038e8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/selectivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/react/single.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit 42038e8

Please sign in to comment.