Skip to content

Commit

Permalink
table.plugin.CellEditing: leaving an editor via Enter or Escape needs…
Browse files Browse the repository at this point in the history
… to restore the cell selection & focus #6165
  • Loading branch information
tobiu committed Dec 18, 2024
1 parent 9b913d0 commit 249cefa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
5 changes: 1 addition & 4 deletions src/form/field/Base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/form/field/Date.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 21 additions & 17 deletions src/table/plugin/CellEditing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -129,7 +130,7 @@ class CellEditing extends Plugin {
hideLabel: true,
parentId : view.id,
record,
value : record[dataField],
value,
windowId,

keys: {
Expand All @@ -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;
Expand Down Expand Up @@ -178,8 +180,11 @@ class CellEditing extends Plugin {
* @returns {Promise<void>}
*/
async onEditorKeyEnter(data, field) {
await this.submitEditor();
this.selectCell(data)
let me = this;

await me.submitEditor();
await me.timeout(20);
me.selectCell(data)
}

/**
Expand All @@ -188,8 +193,11 @@ class CellEditing extends Plugin {
* @returns {Promise<void>}
*/
async onEditorKeyEscape(data, field) {
await this.unmountEditor();
this.selectCell(data)
let me = this;

await me.unmountEditor();
await me.timeout(20);
me.selectCell(data)
}

/**
Expand Down Expand Up @@ -286,19 +294,15 @@ class CellEditing extends Plugin {
* @returns {Promise<void>}
*/
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()
}
}
}
Expand Down

0 comments on commit 249cefa

Please sign in to comment.