Skip to content

Commit 593d777

Browse files
committed
luci: Make password reveal work with passsword managers
Password managers (like LastPass etc) tend to add additional elements into the DOM for their own context menus. If this happens between the hide/reveal button and the password input, then the logic to reveal the password breaks. This change updates the onclick handler to look backward in the DOM for the first sibling that is an input, and to then toggle the password/text type on that element. Signed-off-by: Andrew Dodd <[email protected]>
1 parent 8b3c13f commit 593d777

File tree

2 files changed

+13
-3
lines changed
  • applications/luci-app-dockerman/luasrc/view/dockerman/cbi
  • modules/luci-base/htdocs/luci-static/resources

2 files changed

+13
-3
lines changed

applications/luci-app-dockerman/luasrc/view/dockerman/cbi/inlinevalue.htm

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
ifattr(#self.keylist > 0, "data-choices", { self.keylist, self.vallist })
2929
%> />
3030
<%- if self.password then -%>
31-
<div class="btn cbi-button cbi-button-neutral" title="<%:Reveal/hide password%>" onclick="var e = this.previousElementSibling; e.type = (e.type === 'password') ? 'text' : 'password'"></div>
31+
<div class="btn cbi-button cbi-button-neutral" title="<%:Reveal/hide password%>" onclick="var e = this.previousElementSibling; while (e && e.tagName !== 'INPUT') { e = e.previousElementSibling; }; e.type = (e.type === 'password') ? 'text' : 'password'"></div>
3232
<% end %>
3333
</div>

modules/luci-base/htdocs/luci-static/resources/ui.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,18 @@ var UITextfield = UIElement.extend(/** @lends LuCI.ui.Textfield.prototype */ {
386386
'title': _('Reveal/hide password'),
387387
'aria-label': _('Reveal/hide password'),
388388
'click': function(ev) {
389-
var e = this.previousElementSibling;
390-
e.type = (e.type === 'password') ? 'text' : 'password';
389+
let e = this.previousElementSibling;
390+
// DOM manipulation (e.g. by password managers) may have inserted other
391+
// elements between the reveal button and the input. This searches for
392+
// the first previous sibling that is also an input.
393+
while (e && e.tagName !== 'INPUT') {
394+
e = e.previousElementSibling;
395+
}
396+
if (e) {
397+
e.type = (e.type === 'password') ? 'text' : 'password';
398+
} else {
399+
console.error("unable to find input corresponding to reveal/hide button");
400+
}
391401
ev.preventDefault();
392402
}
393403
}, '∗')

0 commit comments

Comments
 (0)