From 6b995586fdc25b146bd46470fe74c38a37d24347 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Thu, 9 Mar 2017 00:22:26 +0000 Subject: [PATCH] Fix submission of edit form by enter key. Fixes #341~ --- webextension/js/popup.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/webextension/js/popup.js b/webextension/js/popup.js index c75985c..d312565 100644 --- a/webextension/js/popup.js +++ b/webextension/js/popup.js @@ -481,22 +481,28 @@ Logic.registerPanel(P_CONTAINER_EDIT, { Logic.showPreviousPanel(); }); - document.querySelector("#edit-container-ok-link").addEventListener("click", () => { - const identity = Logic.currentIdentity(); - const formValues = new FormData(document.getElementById("edit-container-panel-form")); - browser.runtime.sendMessage({ - method: identity.userContextId ? "updateIdentity" : "createIdentity", - userContextId: identity.userContextId || 0, - name: document.getElementById("edit-container-panel-name-input").value || Logic.generateIdentityName(), - icon: formValues.get("container-icon") || DEFAULT_ICON, - color: formValues.get("container-color") || DEFAULT_COLOR, - }).then(() => { - return Logic.refreshIdentities(); - }).then(() => { - Logic.showPreviousPanel(); - }).catch(() => { - Logic.showPanel(P_CONTAINERS_LIST); - }); + this._editForm = document.getElementById("edit-container-panel-form"); + const editLink = document.querySelector("#edit-container-ok-link"); + editLink.addEventListener("click", this._submitForm); + editLink.addEventListener("submit", this._submitForm); + this._editForm.addEventListener("submit", this._submitForm); + }, + + _submitForm() { + const identity = Logic.currentIdentity(); + const formValues = new FormData(this._editForm); + browser.runtime.sendMessage({ + method: identity.userContextId ? "updateIdentity" : "createIdentity", + userContextId: identity.userContextId || 0, + name: document.getElementById("edit-container-panel-name-input").value || Logic.generateIdentityName(), + icon: formValues.get("container-icon") || DEFAULT_ICON, + color: formValues.get("container-color") || DEFAULT_COLOR, + }).then(() => { + return Logic.refreshIdentities(); + }).then(() => { + Logic.showPreviousPanel(); + }).catch(() => { + Logic.showPanel(P_CONTAINERS_LIST); }); },