main.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //debugger;
  2. function Password (parent, open) {
  3. const inputPassword = document.createElement('input');
  4. const buttonSeePassword = document.createElement('button');
  5. const iputPassword1 = document.createElement('input');
  6. inputPassword.placeholder = 'password';
  7. iputPassword1.placeholder = 'login';
  8. parent.append(inputPassword);
  9. parent.append(iputPassword1);
  10. parent.appendChild(buttonSeePassword).innerText = 'see password';
  11. const buttonCheck = document.createElement('button');
  12. parent.append(buttonCheck);
  13. buttonCheck.innerHTML= 'submit';
  14. buttonCheck.setAttribute('disabled',true);
  15. buttonSeePassword.onclick = () => {
  16. inputPassword.type === 'password' ? inputPassword.type = 'text' : inputPassword.type = 'password';
  17. this.hiddenInput2();
  18. };
  19. let value = null;
  20. this.setValue = newvalue => value = newvalue;
  21. this.getValue = () => value;
  22. let valueOpen = null;
  23. this.setOpen = newvalue => {
  24. this.onOpenChange(newvalue);
  25. open = newvalue;
  26. open ? (inputPassword.type = 'password', valueOpen = open):(inputPassword.type = 'text', valueOpen = open);
  27. };
  28. this.getOpen = () => valueOpen;
  29. this.onChange = function (data) {
  30. data = inputPassword.value;
  31. console.log(data);
  32. };
  33. inputPassword.oninput = () => {
  34. this.onChange();
  35. this.checkPassword();
  36. }
  37. this.onOpenChange = open => console.log(open);
  38. this.checkPassword = function () {
  39. if(inputPassword.value === iputPassword1.value) { console.log(inputPassword.value, iputPassword1.value)
  40. buttonCheck.removeAttribute("disabled");
  41. } else {buttonCheck.setAttribute('disabled',true)};
  42. }
  43. iputPassword1.oninput = this.checkPassword;
  44. this.hiddenInput2 = () => {
  45. if (inputPassword.type === 'text') {
  46. iputPassword1.style.visibility = 'hidden';
  47. } else iputPassword1.style.visibility = 'visible';
  48. }
  49. };
  50. let p = new Password(document.body, true);
  51. p.setValue('qwerty');
  52. console.log(p.getValue());
  53. p.setOpen(false);
  54. console.log(p.getOpen());
  55. p.setOpen(true);
  56. //Task LoginForm
  57. // let newP = new Password(document.body);
  58. // const buttonCheck = document.createElement('button');
  59. // document.body.append(buttonCheck);
  60. // buttonCheck.innerHTML= 'submit';
  61. // const inputList = document.getElementsByTagName('input');
  62. // const inputPassword2 = inputList[2];
  63. // const inputPassword3 = inputList[3];
  64. // buttonCheck.setAttribute('disabled',true);
  65. // const checkEnterLoginPassword = function () {
  66. // if (!(inputPassword2.value === '') && !(inputPassword3.value === "")) {
  67. // buttonCheck.removeAttribute("disabled");
  68. // };
  69. // }
  70. // inputPassword2.oninput = checkEnterLoginPassword;
  71. // inputPassword3.oninput = checkEnterLoginPassword;
  72. //LoginForm Constructor
  73. function LoginForm (parent) {
  74. const inputPassword = document.createElement('input');
  75. const buttonSeePassword = document.createElement('button');
  76. const iputPassword1 = document.createElement('input');
  77. inputPassword.placeholder = 'password';
  78. iputPassword1.placeholder = 'login';
  79. parent.append(inputPassword);
  80. parent.append(iputPassword1);
  81. parent.appendChild(buttonSeePassword).innerText = 'see password';
  82. const buttonCheck = document.createElement('button');
  83. parent.append(buttonCheck);
  84. buttonCheck.innerHTML= 'submit';
  85. const inputList = document.getElementsByTagName('input');
  86. const inputPassword2 = inputList[2];
  87. const inputPassword3 = inputList[3];
  88. buttonCheck.setAttribute('disabled',true);
  89. this.checkEnterLoginPassword = function () {
  90. if (!(inputPassword2.value === '') && !(inputPassword3.value === "")) {
  91. buttonCheck.removeAttribute("disabled");
  92. };
  93. }
  94. inputPassword2.oninput = this.checkEnterLoginPassword;
  95. inputPassword3.oninput = this.checkEnterLoginPassword;
  96. let password = null;
  97. }
  98. let obj = new LoginForm(document.body);
  99. //Password Verify add to task 1
  100. let obj2 = new Password(document.body);
  101. let obj3 = new Password(document.body);
  102. obj2.setOpen(true);
  103. obj3.setOpen(true);