Skip to content

Commit

Permalink
Merge pull request #367 from ghiscoding/bugfix/select-editor-undefine…
Browse files Browse the repository at this point in the history
…d-value

fix(editors): select dropdown value is undefined it shouldn't call save
  • Loading branch information
ghiscoding authored Jun 2, 2021
2 parents bfdc295 + 015294b commit 4b979dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/common/src/editors/__tests__/singleSelectEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ describe('SingleSelectEditor', () => {
});

describe('isValueChanged method', () => {
it('should return False if the value is undefined', () => {
editor = new SingleSelectEditor(editorArguments);
const editorBtnElm = divContainer.querySelector('.ms-parent.ms-filter.editor-gender button.ms-choice') as HTMLButtonElement;
const editorListElm = divContainer.querySelectorAll<HTMLInputElement>(`[name=editor-gender].ms-drop ul>li input[type=radio]`);
editorBtnElm.click();

// we can use property "checked" or dispatch an event
editorListElm[0].checked = false;

expect(editor.isValueChanged()).toBe(false);
});

it('should return True after doing a check of an option', () => {
editor = new SingleSelectEditor(editorArguments);
const editorBtnElm = divContainer.querySelector('.ms-parent.ms-filter.editor-gender button.ms-choice') as HTMLButtonElement;
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/editors/selectEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class SelectEditor implements Editor {
}

destroy() {
// when autoCommitEdit is enabled, we might end up leave the editor without it being saved, if so do call a save before destroying
// when autoCommitEdit is enabled, we might end up leaving an editor without it being saved, if so do call a save before destroying
// this mainly happens doing a blur or focusing on another cell in the grid (it won't come here if we click outside the grid, in the body)
if (this.$editorElm && this.hasAutoCommitEdit && this.isValueChanged() && !this._isDisposing && !this.isCompositeEditor) {
this._isDisposing = true; // change destroying flag to avoid infinite loop
Expand Down Expand Up @@ -517,7 +517,7 @@ export class SelectEditor implements Editor {
return !isEqual;
}
const value = Array.isArray(valueSelection) && valueSelection.length > 0 ? valueSelection[0] : undefined;
return value !== this.originalValue;
return value !== undefined && value !== this.originalValue;
}

isValueTouched(): boolean {
Expand Down
Binary file not shown.

0 comments on commit 4b979dd

Please sign in to comment.