|
@@ -9,20 +9,33 @@
|
|
|
<body>
|
|
|
<script>
|
|
|
|
|
|
- function Password(parent, open){
|
|
|
+ function Password(parent, open){
|
|
|
const pass = document.createElement('input')
|
|
|
- const button = document.createElement('button')
|
|
|
- const logn = document.createElement('input')
|
|
|
- pass.placeholder = "Enter your password"
|
|
|
- logn.placeholder = "Enter your login"
|
|
|
- button.innerText = 'Hide'
|
|
|
- parent.prepend(button)
|
|
|
+ const btn = document.createElement('button')
|
|
|
+ const lgn = document.createElement('input')
|
|
|
+ const sbmt = document.createElement('button')
|
|
|
+ sbmt.innerText = 'Submit'
|
|
|
+ lgn.placeholder = "login"
|
|
|
+ pass.placeholder = "password"
|
|
|
+ btn.innerText = 'Show'
|
|
|
+ parent.prepend(sbmt)
|
|
|
+ parent.prepend(btn)
|
|
|
parent.prepend(pass)
|
|
|
- parent.prepend(logn)
|
|
|
- button.addEventListener('click', () => this.setOpen(!this.open))
|
|
|
- button.addEventListener('click', () => {
|
|
|
- button.innerText = (button.innerText === 'Hide') ? button.innerText = 'Show' : button.innerText = 'Hide';
|
|
|
+ parent.prepend(lgn)
|
|
|
+ btn.addEventListener('click', () => this.setOpen(!this.open))
|
|
|
+ btn.addEventListener('click', () => {
|
|
|
+ btn.innerText = (btn.innerText === 'Show') ? btn.innerText = 'Hide' : btn.innerText = 'Show';
|
|
|
})
|
|
|
+ sbmt.setAttribute('disabled', true)
|
|
|
+ oninput = () =>{
|
|
|
+ if(pass.value.length < 1 || lgn.value.length < 1 ){
|
|
|
+ sbmt.setAttribute('disabled', true)
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sbmt.removeAttribute('disabled')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
this.open = open
|
|
|
this .setOpen = (value) => {
|
|
|
this.open = value
|
|
@@ -34,12 +47,13 @@ this.open = open
|
|
|
|
|
|
const render = () => {
|
|
|
pass.setAttribute('type', `${this.open ? 'text' : 'password'}`);
|
|
|
- logn.setAttribute('type', `${this.open ? 'text' : 'password'}` );
|
|
|
+ lgn.setAttribute('type', `${this.open ? 'text' : 'password'}` );
|
|
|
}
|
|
|
return render()
|
|
|
}
|
|
|
|
|
|
-let p = new Password(document.body, true)
|
|
|
+let p = new Password(document.body, false)
|
|
|
+
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|