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(editors): select dropdown value is undefined it shouldn't call save #367

Merged
merged 1 commit into from
Jun 2, 2021
Merged
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
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.