Giter Site home page Giter Site logo

Comments (2)

eduo avatar eduo commented on May 29, 2024

Depending on the browser, you might get the widget to make the password visible automatically.

I just tried this schema and I got this in ·Edge:

image image

Alternatively, you can set a watcher for password fields where if length > 0 an icon is added to the input, and to that icon add an event listener for click to switch icons and to change the type from password to text and viceversa.

Alternatively, you could scan all your password fields and append a toggable eye when there isn't one already.

You can put this in your change event for the editor:

editor.on('change', function() { 
document.querySelectorAll("[type=password]").forEach((thisField,eid) => {
	if(!thisField.parentElement.querySelectorAll('i.eyetoggle').length>0) {
		thisIcon=document.createElement('i');
		thisIcon.addEventListener('click',function(){ 
			if(thisField.type === "password") {
				thisField.type = "text";
				this.classList.add("fa-eye-slash");
				this.classList.remove("fa-eye");
			} else {
				thisField.type = "password";
				this.classList.add("fa-eye");
				this.classList.remove("fa-eye-slash");
			}});
			thisField.style.display='inline-block';
			thisField.style.width='90%'
			thisIcon.style.zIndex=2
			thisIcon.classList.add('eyetoggle');
			thisIcon.classList.add('fa');
			thisIcon.classList.add('fa-eye');
			thisField.parentElement.append(thisIcon)
		}
	}
)
}


(of course, you should modify the style to work for you, and perhaps put a timer in the click event so it automatically turns back to password field).

Edit: Some formatting, since I wrote this in a rush in the developer tools console :D
Edit2: Modified input field to be inline block and 90% width to accomodate the icon after it, but you can do your own styling.

from json-editor.

alfian444 avatar alfian444 commented on May 29, 2024

Depending on the browser, you might get the widget to make the password visible automatically.

I just tried this schema and I got this in ·Edge:

image image
Alternatively, you can set a watcher for password fields where if length > 0 an icon is added to the input, and to that icon add an event listener for click to switch icons and to change the type from password to text and viceversa.

Alternatively, you could scan all your password fields and append a toggable eye when there isn't one already.

You can put this in your change event for the editor:

editor.on('change', function() { 
document.querySelectorAll("[type=password]").forEach((thisField,eid) => {
	if(!thisField.parentElement.querySelectorAll('i.eyetoggle').length>0) {
		thisIcon=document.createElement('i');
		thisIcon.addEventListener('click',function(){ 
			if(thisField.type === "password") {
				thisField.type = "text";
				this.classList.add("fa-eye-slash");
				this.classList.remove("fa-eye");
			} else {
				thisField.type = "password";
				this.classList.add("fa-eye");
				this.classList.remove("fa-eye-slash");
			}});
			thisField.style.display='inline-block';
			thisField.style.width='90%'
			thisIcon.style.zIndex=2
			thisIcon.classList.add('eyetoggle');
			thisIcon.classList.add('fa');
			thisIcon.classList.add('fa-eye');
			thisField.parentElement.append(thisIcon)
		}
	}
)
}

(of course, you should modify the style to work for you, and perhaps put a timer in the click event so it automatically turns back to password field).

Edit: Some formatting, since I wrote this in a rush in the developer tools console :D Edit2: Modified input field to be inline block and 90% width to accomodate the icon after it, but you can do your own styling.

Thank you for the answer, this really helped me :D

from json-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.