From 3318acd16beb5a5b1f82fda5291318623dfda30d Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 9 Jan 2017 16:24:04 +0000 Subject: [PATCH] fix filling in nickname overriding username (in add network tab) --- client/js/lounge.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/client/js/lounge.js b/client/js/lounge.js index 774aeddd..754ab1a4 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -1283,9 +1283,27 @@ $(function() { ); }); + forms.on("focusin", ".nick", function() { + // Need to set the first "lastvalue", so it can be used in the below function + var nick = $(this); + nick.data("lastvalue", nick.val()); + }); + forms.on("input", ".nick", function() { var nick = $(this).val(); - forms.find(".username").val(nick); + var usernameInput = forms.find(".username"); + + // Because this gets called /after/ it has already changed, we need use the previous value + var lastValue = $(this).data("lastvalue"); + + // They were the same before the change, so update the username field + if (usernameInput.val() === lastValue) { + usernameInput.val(nick); + } + + // Store the "previous" value, for next time + $(this).data("lastvalue", nick); + }); Mousetrap.bind([