Skip to content

Commit

Permalink
FIX TreeDropdownField fails validation if it is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Sep 14, 2023
1 parent c9913dc commit 2862842
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
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

0 comments on commit 2862842

Please sign in to comment.