Skip to content
Advertisement

Combine Primefaces passwords validation: and show/hide text/password icon together

I’m trying to set a password validation in Primefaces using p:password and I need to add the show password eye icon too.
I need something like the picture below, show or hide the text/password when user clicks cursor.

p:password example

PRIMEFACES JSF code:

JavaScript



JAVASCRIPT code:

JavaScript

I don’t know how to change the text to password and vice versa using javascript and p:password, and I don´t know how to enable/disable the show-pass and hide-pass icon when the user clicks the icon.

Advertisement

Answer

It is way simpler than that you don’t need to remove the attribute just change it. Using JQuery. In the example below your pwd1 is in an h:form called “frmPassword” and name your button id=”button1″.

JavaScript

Edit 10/11/2021: This is built into PrimeFaces 10 as toggleMask feature. See Showcase: http://primefaces.org/showcase/ui/input/password.xhtml

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement