Skip to content

Commit

Permalink
Fix: Inline metadata edit, only update if enter or tab key pressed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsadam authored Jan 8, 2025
1 parent ae1712b commit a8d5c1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
21 changes: 12 additions & 9 deletions app/javascript/controllers/inline_edit_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ export default class extends Controller {
}

submit() {
if (!this.submitted) {
this.element.requestSubmit();
}
this.element.requestSubmit();
}

reset() {
this.inputTarget.value = this.originalValue;
this.submit();
}

cancel(event) {
if (event.key === "Escape") {
this.inputTarget.value = this.originalValue;
this.inputTarget.blur();
} else if (event.key === "Enter") {
this.submitted = true;
inputKeydown(event) {
if(event.key === "Escape") {
this.reset();
} else if(event.key === "Tab") {
event.preventDefault();
this.submit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"w-full m-0 border-slate-300 text-slate-900 text-sm focus:ring-primary-500 focus:border-primary-500 block w-full p-2.5 dark:bg-slate-700 dark:border-slate-600 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500",
data: {
"inline-edit-target": "input",
action: "blur->inline-edit#submit keydown->inline-edit#cancel",
action:
"blur->inline-edit#reset keydown->inline-edit#inputKeydown",
} %>
<% end %>
</td>

0 comments on commit a8d5c1f

Please sign in to comment.