From a81aa257104970a2ced2994eded66da43d6300f6 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Thu, 22 Sep 2022 12:40:58 +0300 Subject: [PATCH] Fix saving Custom Login Fields --- .../content/custom-fields-banner.js | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/keepassxc-browser/content/custom-fields-banner.js b/keepassxc-browser/content/custom-fields-banner.js index f51fd20..71fbad5 100644 --- a/keepassxc-browser/content/custom-fields-banner.js +++ b/keepassxc-browser/content/custom-fields-banner.js @@ -323,39 +323,41 @@ kpxcCustomLoginFieldsBanner.confirm = async function() { const location = kpxc.getDocumentLocation(); const currentSettings = kpxc.settings[DEFINED_CUSTOM_FIELDS][location]; - if (currentSettings) { - // Update the single selection to current settings - if (usernamePath) { - clearIdenticalField(usernamePath, location); - kpxc.settings[DEFINED_CUSTOM_FIELDS][location].username = usernamePath; + if (usernamePath || passwordPath || totpPath || stringFieldsPaths.length > 0) { + if (currentSettings) { + // Update the single selection to current settings + if (usernamePath) { + clearIdenticalField(usernamePath, location); + kpxc.settings[DEFINED_CUSTOM_FIELDS][location].username = usernamePath; + } + + if (passwordPath) { + clearIdenticalField(passwordPath, location); + kpxc.settings[DEFINED_CUSTOM_FIELDS][location].password = passwordPath; + } + + if (totpPath) { + clearIdenticalField(totpPath, location); + kpxc.settings[DEFINED_CUSTOM_FIELDS][location].totp = totpPath; + } + + if (stringFieldsPaths.length > 0) { + kpxc.settings[DEFINED_CUSTOM_FIELDS][location].fields = stringFieldsPaths; + } + } else { + // Override all fields (default, because there's no currentSettings available) + kpxc.settings[DEFINED_CUSTOM_FIELDS][location] = { + username: usernamePath, + password: passwordPath, + totp: totpPath, + fields: stringFieldsPaths + }; } - if (passwordPath) { - clearIdenticalField(passwordPath, location); - kpxc.settings[DEFINED_CUSTOM_FIELDS][location].password = passwordPath; - } - - if (totpPath) { - clearIdenticalField(totpPath, location); - kpxc.settings[DEFINED_CUSTOM_FIELDS][location].totp = totpPath; - } - - if (stringFieldsPaths.length > 0) { - kpxc.settings[DEFINED_CUSTOM_FIELDS][location].fields = stringFieldsPaths; - } - } else { - // Override all fields (default) - kpxc.settings[DEFINED_CUSTOM_FIELDS][location] = { - username: usernamePath, - password: passwordPath, - totp: totpPath, - fields: stringFieldsPaths - }; + await sendMessage('save_settings', kpxc.settings); } - await sendMessage('save_settings', kpxc.settings); kpxcCustomLoginFieldsBanner.destroy(); - sendMessageToFrames('confirm_button_clicked'); }; @@ -511,7 +513,6 @@ kpxcCustomLoginFieldsBanner.selectStringFields = function() { }; kpxcCustomLoginFieldsBanner.markFields = function() { - let index = 1; let firstInput; const inputs = document.querySelectorAll(kpxcCustomLoginFieldsBanner.inputQueryPattern); @@ -567,7 +568,6 @@ kpxcCustomLoginFieldsBanner.markFields = function() { kpxcCustomLoginFieldsBanner.chooser.append(field); firstInput = field; - ++index; } }