From 249cefa98f23ca9667f8dd2d98a4380ddf8483f3 Mon Sep 17 00:00:00 2001 From: tobiu Date: Wed, 18 Dec 2024 18:40:26 +0100 Subject: [PATCH] table.plugin.CellEditing: leaving an editor via Enter or Escape needs to restore the cell selection & focus #6165 --- src/form/field/Base.mjs | 5 +---- src/form/field/Date.mjs | 3 ++- src/table/plugin/CellEditing.mjs | 38 ++++++++++++++++++-------------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/form/field/Base.mjs b/src/form/field/Base.mjs index 6b52d7a62..d48024a9c 100644 --- a/src/form/field/Base.mjs +++ b/src/form/field/Base.mjs @@ -78,10 +78,7 @@ class Base extends Component { * @returns {Boolean} */ get isDirty() { - let originalValue = this.originalConfig.value, - value = this.value; - - return value !== originalValue && Neo.isEmpty(value) !== Neo.isEmpty(originalValue) + return !Neo.isEqual(this.getSubmitValue(), this.originalConfig.value) } /** * An internal cache for formGroup(s) and the field name diff --git a/src/form/field/Date.mjs b/src/form/field/Date.mjs index bd6081f5d..50a483498 100644 --- a/src/form/field/Date.mjs +++ b/src/form/field/Date.mjs @@ -171,7 +171,8 @@ class DateField extends Picker { */ beforeSetValue(value, oldValue) { if (Neo.typeOf(value) === 'Date') { - value = DateUtil.convertToyyyymmdd(value) + value = DateUtil.convertToyyyymmdd(value); + this.originalConfig.value = value } value = super.beforeSetValue(value, oldValue); diff --git a/src/table/plugin/CellEditing.mjs b/src/table/plugin/CellEditing.mjs index f784e1516..e269a4294 100644 --- a/src/table/plugin/CellEditing.mjs +++ b/src/table/plugin/CellEditing.mjs @@ -109,7 +109,8 @@ class CellEditing extends Plugin { cellId = view.getCellId(record, dataField), cellNode = VdomUtil.find(view.vdom, cellId).vdom, column = me.owner.headerToolbar.getColumn(dataField), - editor = me.editors[dataField]; + editor = me.editors[dataField], + value = record[dataField]; if (me.mountedEditor) { await me.unmountEditor(); @@ -129,7 +130,7 @@ class CellEditing extends Plugin { hideLabel: true, parentId : view.id, record, - value : record[dataField], + value, windowId, keys: { @@ -142,7 +143,8 @@ class CellEditing extends Plugin { ...column.editor }) } else { - editor.setSilent({record, value: record[dataField]}) + editor.originalConfig.value = value; + editor.setSilent({record, value}) } me.mountedEditor = editor; @@ -178,8 +180,11 @@ class CellEditing extends Plugin { * @returns {Promise} */ async onEditorKeyEnter(data, field) { - await this.submitEditor(); - this.selectCell(data) + let me = this; + + await me.submitEditor(); + await me.timeout(20); + me.selectCell(data) } /** @@ -188,8 +193,11 @@ class CellEditing extends Plugin { * @returns {Promise} */ async onEditorKeyEscape(data, field) { - await this.unmountEditor(); - this.selectCell(data) + let me = this; + + await me.unmountEditor(); + await me.timeout(20); + me.selectCell(data) } /** @@ -286,19 +294,15 @@ class CellEditing extends Plugin { * @returns {Promise} */ async submitEditor() { - let field = this.mountedEditor; + let me = this, + field = me.mountedEditor; if (field?.isValid()) { - let fieldValue = field.record[field.dataField]; - - // We only get a record change event => UI update, in case there is a real change - if (fieldValue !== field.value) { - field.record[field.dataField] = field.getSubmitValue(); - - // Short delay to ensure the update OP is done - await this.timeout(50) + if (field.isDirty) { + me.mountedEditor = null; + field.record[field.dataField] = field.getSubmitValue() } else { - await this.unmountEditor() + await me.unmountEditor() } } }