Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX TreeDropdownField fails validation if it is empty #1578

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions client/src/components/TreeDropdownField/TreeDropdownField.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SEARCH_DELAY = 500; // ms
// legacy value for multi-select's empty value
const MULTI_EMPTY_VALUE = 'unchanged';

const SINGLE_EMPTY_VALUE = 0;
const SINGLE_EMPTY_VALUE = '';

class TreeDropdownField extends Component {
constructor(props) {
Expand Down Expand Up @@ -174,7 +174,7 @@ class TreeDropdownField extends Component {
// require an empty option in some instances
// value is an empty string by react-select cannot find the options
options.unshift({
id: this.props.data.multiple ? '' : SINGLE_EMPTY_VALUE,
id: SINGLE_EMPTY_VALUE,
title: (this.props.data.hasEmptyDefault) ? this.props.data.emptyString : null,
disabled: !options.length || !this.props.data.hasEmptyDefault,
});
Expand Down Expand Up @@ -330,7 +330,7 @@ class TreeDropdownField extends Component {
const parent = this.getVisibleTree();

return options.filter((option) => {
if ((option.id === SINGLE_EMPTY_VALUE || option.id === '') &&
if ((option.id === SINGLE_EMPTY_VALUE) &&
(!this.props.data.hasEmptyDefault || this.props.visible.length || this.hasSearch())
) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ describe('TreeDropdownField', () => {
<TreeDropdownField {...props} />
);
const options = field.getDropdownOptions();
expect(options[0].id).toBe(0);
expect(options[0].id).toBe('');
});

it('should return an empty first option if node has no children', () => {
Expand All @@ -506,7 +506,7 @@ describe('TreeDropdownField', () => {
const options = field.getDropdownOptions();

expect(options.length).toBe(1);
expect(options[0].id).toBe(0);
expect(options[0].id).toBe('');
expect(options[0].title).toBe(null);
expect(options[0].disabled).toBe(true);
});
Expand Down