mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Disable "enter" hotkeys only on tag input element
We are still able to use enter to submit the form on anyother input.The tag input creates a new tag when enter is pressed
This commit is contained in:
@@ -3,6 +3,14 @@ import { Controller } from "stimulus";
|
||||
export default class extends Controller {
|
||||
static targets = ["tagList", "newTag", "template", "list"];
|
||||
|
||||
connect() {
|
||||
// form hotkeys are enabled for "input" scope, we disable the form submit via enter
|
||||
// on the tag input, so we can use the enter key to create new product tag
|
||||
hotkeys("enter", { scope: "input", element: this.newTagTarget }, function () {
|
||||
event.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
addTag() {
|
||||
// Check if tag already exist
|
||||
const newTagName = this.newTagTarget.value;
|
||||
|
||||
@@ -23,11 +23,6 @@ export default class BulkFormController extends Controller {
|
||||
recordElements = {};
|
||||
|
||||
connect() {
|
||||
// disable form submit via enter key, so we can use enter key to create new product tags
|
||||
hotkeys("enter", function (event, handler) {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
this.submitting = false;
|
||||
this.form = this.element;
|
||||
|
||||
|
||||
@@ -9,14 +9,6 @@ describe("BulkFormController", () => {
|
||||
beforeAll(() => {
|
||||
const application = Application.start();
|
||||
application.register("bulk-form", bulk_form_controller);
|
||||
|
||||
// Mock hotkeys.js
|
||||
const mockedHotkeys = jest.fn();
|
||||
global.hotkeys = mockedHotkeys;
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
delete global.hotkeys;
|
||||
});
|
||||
|
||||
describe("Modifying input values", () => {
|
||||
|
||||
@@ -9,6 +9,14 @@ describe("TagListInputController", () => {
|
||||
beforeAll(() => {
|
||||
const application = Application.start();
|
||||
application.register("tag-list-input-component--tag-list-input", tag_list_input_controller);
|
||||
|
||||
// Mock hotkeys.js
|
||||
const mockedHotkeys = jest.fn();
|
||||
global.hotkeys = mockedHotkeys;
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
delete global.hotkeys;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user