123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Document</title>
- </head>
- <body>
- <div id="formContainer"></div>
- <script>
- //PASSWORD
- // function Password(parent, open) {
- // let formBody = document.createElement("div");
- // let passwordInput = document.createElement("input");
- // let isOpenInput = document.createElement("input");
- // parent.append(formBody);
- // passwordInput.type = open ? "text" : "password";
- // passwordInput.oninput = () => {
- // this.value = passwordInput.value;
- // if (typeof this.onChange === "function") {
- // this.onChange(this.value);
- // }
- // };
- // isOpenInput.type = "checkbox";
- // isOpenInput.checked = open;
- // isOpenInput.onchange = () => {
- // this.open = isOpenInput.checked;
- // passwordInput.type = this.open ? "text" : "password";
- // if (typeof this.onOpenChange === "function") {
- // this.onOpenChange(this.open);
- // }
- // };
- // const setValue = (value) => {
- // this.value = value;
- // passwordInput.value = this.value;
- // };
- // const getValue = () => {
- // return this.value;
- // };
- // const setOpen = (value) => {
- // this.open = value;
- // isOpenInput.checked = value;
- // passwordInput.type = this.open ? "text" : "password";
- // };
- // const getOpen = () => {
- // return this.open;
- // };
- // formBody.append(passwordInput);
- // formBody.append(isOpenInput);
- // this.open = open;
- // this.setValue = setValue;
- // this.getValue = getValue;
- // this.setOpen = setOpen;
- // this.getOpen = getOpen;
- // this.value = passwordInput.value;
- // }
- // let p = new Password(document.body, true);
- // p.onChange = (data) => console.log(data);
- // p.onOpenChange = (open) => console.log(open);
- // p.setValue("qwerty");
- // console.log(p.getValue());
- // p.setOpen(false);
- // console.log(p.getOpen());
- //LoginForm
- // function LoginForm(parent, open) {
- // let formBody = document.createElement("div");
- // let passwordInput = document.createElement("input");
- // let loginInput = document.createElement("input");
- // let isOpenInput = document.createElement("input");
- // let loginButton = document.createElement("button");
- // parent.append(formBody);
- // passwordInput.type = open ? "text" : "password";
- // passwordInput.oninput = () => {
- // this.passwordValue = passwordInput.value;
- // loginButton.disabled = checkIfBlank();
- // if (typeof this.onPasswordChange === "function") {
- // this.onPasswordChange(this.passwordValue);
- // }
- // };
- // loginInput.type = "text";
- // loginInput.oninput = () => {
- // this.loginValue = loginInput.value;
- // loginButton.disabled = checkIfBlank();
- // if (typeof this.onLoginChange === "function") {
- // this.onLoginChange(this.loginValue);
- // }
- // };
- // isOpenInput.type = "checkbox";
- // isOpenInput.checked = open;
- // isOpenInput.onchange = () => {
- // this.open = isOpenInput.checked;
- // passwordInput.type = this.open ? "text" : "password";
- // if (typeof this.onOpenChange === "function") {
- // this.onOpenChange(this.open);
- // }
- // };
- // loginButton.innerText = "Login";
- // const setPasswordValue = (value) => {
- // this.passwordValue = value;
- // passwordInput.value = this.passwordValue;
- // };
- // const getPasswordValue = () => {
- // return this.passwordValue;
- // };
- // const setLoginValue = (value) => {
- // this.loginValue = value;
- // loginInput.value = this.loginValue;
- // };
- // const getLoginValue = () => {
- // return this.loginValue;
- // };
- // const setOpen = (value) => {
- // this.open = value;
- // isOpenInput.checked = value;
- // passwordInput.type = this.open ? "text" : "password";
- // };
- // const getOpen = () => {
- // return this.open;
- // };
- // const checkIfBlank = () => {
- // if (this.loginValue.trim().length === 0 || this.passwordValue.trim().length === 0) {
- // return true;
- // }
- // return false;
- // };
- // formBody.append(loginInput);
- // formBody.append(passwordInput);
- // formBody.append(isOpenInput);
- // formBody.append(loginButton);
- // this.open = open;
- // this.setPasswordValue = setPasswordValue;
- // this.getPasswordValue = getPasswordValue;
- // this.setLoginValue = setLoginValue;
- // this.getLoginValue = getLoginValue;
- // this.setOpen = setOpen;
- // this.getOpen = getOpen;
- // this.passwordValue = passwordInput.value;
- // this.loginValue = loginInput.value;
- // loginButton.disabled = checkIfBlank();
- // }
- // let p = new LoginForm(document.body, true);
- // p.onPasswordChange = (data) => console.log(data);
- // p.onOpenChange = (open) => console.log(open);
- // p.onLoginChange = (data) => console.log(data);
- // p.setPasswordValue("qwerty");
- // console.log(p.getPasswordValue());
- // p.setLoginValue("qwerty");
- // console.log(p.getLoginValue());
- // p.setOpen(false);
- // console.log(p.getOpen());
- //PASSWORD VERIFY
- // function Password(parent, open) {
- // let formBody = document.createElement("div");
- // let passwordInput1 = document.createElement("input");
- // let passwordInput2 = document.createElement("input");
- // let isOpenInput = document.createElement("input");
- // let checkButton = document.createElement("button");
- // parent.append(formBody);
- // checkButton.innerText = "checkButton";
- // passwordInput1.type = open ? "text" : "password";
- // passwordInput1.oninput = () => {
- // this.value1 = passwordInput1.value;
- // checkButton.disabled = !isValid();
- // if (typeof this.onPassword1Change === "function") {
- // this.onPassword1Change(this.value1);
- // }
- // };
- // passwordInput2.type = "password";
- // passwordInput2.style.display = !open ? "inline" : "none";
- // passwordInput2.oninput = () => {
- // this.value2 = passwordInput2.value;
- // checkButton.disabled = !isValid();
- // console.log(isValid());
- // if (typeof this.onPassword2Change === "function") {
- // this.onPassword2Change(this.value2);
- // }
- // };
- // isOpenInput.type = "checkbox";
- // isOpenInput.checked = open;
- // isOpenInput.onchange = () => {
- // this.open = isOpenInput.checked;
- // checkButton.disabled = !isValid();
- // passwordInput1.type = this.open ? "text" : "password";
- // passwordInput2.style.display = !this.open ? "inline" : "none";
- // if (typeof this.onOpenChange === "function") {
- // this.onOpenChange(this.open);
- // }
- // };
- // const setValue1 = (newValue) => {
- // this.value1 = newValue;
- // passwordInput1.value = newValue;
- // checkButton.disabled = !isValid();
- // };
- // const setValue2 = (newValue) => {
- // this.value2 = newValue;
- // passwordInput2.value = newValue;
- // checkButton.disabled = !isValid();
- // };
- // const getValue1 = () => {
- // return this.value1;
- // };
- // const getValue2 = () => {
- // return this.value2;
- // };
- // const setOpen = (value) => {
- // this.open = value;
- // isOpenInput.checked = value;
- // passwordInput1.type = this.open ? "text" : "password";
- // passwordInput2.style.display = !this.open ? "inline" : "none";
- // checkButton.disabled = !isValid();
- // };
- // const getOpen = () => {
- // return this.open;
- // };
- // const isValid = () => {
- // if (this.open === true) {
- // return false;
- // }
- // if (this.value1 === this.value2 && this.value1.trim() !== "" && this.value2.trim()) {
- // return true;
- // }
- // return false;
- // };
- // formBody.append(passwordInput1);
- // formBody.append(passwordInput2);
- // formBody.append(isOpenInput);
- // formBody.append(checkButton);
- // this.open = open;
- // this.value1 = passwordInput1.value;
- // this.value2 = passwordInput2.value;
- // this.setOpen = setOpen;
- // this.getOpen = getOpen;
- // this.setValue1 = setValue1;
- // this.getValue1 = getValue1;
- // this.setValue2 = setValue2;
- // this.getValue2 = getValue2;
- // checkButton.disabled = !isValid();
- // }
- // let p = new Password(document.body, true);
- // p.onPassword1Change = (data) => console.log(data);
- // p.onPassword2Change = (data) => console.log(data);
- // p.onOpenChange = (open) => console.log(open);
- // p.setValue1("qwerty");
- // console.log(p.getValue1());
- // p.setValue2("qwer");
- // console.log(p.getValue2());
- // p.setOpen(false);
- // console.log(p.getOpen());
- //FORM
- // function Form(el, data, okCallback, cancelCallback) {
- // let formBody = document.createElement("div");
- // let inputBox = document.createElement("div");
- // let okButton = document.createElement("button");
- // let validatorErrors = new Set();
- // let requiredErrors = new Set();
- // let cancelButton = document.createElement("button");
- // let initData = { ...data };
- // okButton.innerHTML = "OK";
- // cancelButton.innerHTML = "Cancel";
- // el.appendChild(formBody);
- // formBody.append(inputBox);
- // let inputCreators = {
- // String(key, value, oninput) {
- // if (value.length > 20) {
- // let textarea = document.createElement("textarea");
- // textarea.value = value;
- // textarea.oninput = () => oninput(textarea.value);
- // return textarea;
- // } else {
- // let input = document.createElement("input");
- // input.type = "text";
- // if ([...value].every((el) => el === "*")) {
- // input.type = "password";
- // }
- // input.placeholder = key;
- // input.value = value;
- // input.oninput = () => oninput(input.value);
- // return input;
- // }
- // },
- // Boolean(key, value, oninput) {
- // let input = document.createElement("input");
- // input.type = "checkbox";
- // input.checked = value;
- // input.oninput = () => oninput(Boolean(input.checked));
- // return input;
- // },
- // Date(key, value, oninput) {
- // let input = document.createElement("input");
- // let timeOffset = new Date().getTimezoneOffset();
- // let dateInMillSec =
- // new Date(value.toISOString()).getTime() - new Date().getTimezoneOffset() * 1000 * 60;
- // input.type = "datetime-local";
- // input.value = new Date(dateInMillSec).toISOString().slice(0, 16);
- // input.oninput = () => oninput(new Date(input.value));
- // return input;
- // },
- // };
- // let createInputs = (data) => {
- // inputBox.innerHTML = "";
- // for (let [key, value] of Object.entries(data)) {
- // let inputWrapper = document.createElement("div");
- // let inputType = value.constructor.name;
- // let th = document.createElement("th");
- // let inputLabel = document.createElement("label");
- // let isRequired = key.trim()[0] === "*";
- // let isRequiredChar = document.createElement("span");
- // inputLabel.style.marginLeft = "5px";
- // isRequiredChar.innerText = "* ";
- // isRequiredChar.style.color = "red";
- // if (isRequired) {
- // th.prepend(isRequiredChar);
- // }
- // th.innerHTML += isRequired ? key.slice(1, key.length) : key;
- // let input = inputCreators[inputType](key, value, (value) => {
- // let validator;
- // if (isRequired && value.trim().length === 0) {
- // input.style.border = "1px solid red";
- // requiredErrors.add(key);
- // } else {
- // requiredErrors.delete(key);
- // }
- // if (this.validators && typeof this.validators[key] === "function") {
- // validator = this.validators[key];
- // }
- // if (validator) {
- // let validResult = validator(value, key, data, input);
- // if (validResult !== true && validResult.trim() !== "") {
- // inputLabel.innerText = validResult;
- // inputLabel.style.border = "1px solid red";
- // validatorErrors.add(key);
- // } else {
- // inputLabel.innerText = "";
- // inputLabel.style.border = "none";
- // validatorErrors.delete(key);
- // }
- // }
- // inputWrapper.append(inputLabel);
- // !validatorErrors.has(key) && (this.data[key] = value);
- // okButton.disabled = checkErrors();
- // });
- // inputWrapper.appendChild(th);
- // inputWrapper.appendChild(input);
- // inputBox.append(inputWrapper);
- // }
- // };
- // createInputs(data);
- // okButton.disabled = checkErrors();
- // function checkErrors() {
- // if (requiredErrors.size === 0 && validatorErrors.size === 0) {
- // return false;
- // }
- // return true;
- // }
- // if (typeof okCallback === "function") {
- // formBody.appendChild(okButton);
- // okButton.onclick = (e) => {
- // this.okCallback(data);
- // };
- // }
- // if (typeof cancelCallback === "function") {
- // formBody.appendChild(cancelButton);
- // cancelButton.onclick = () => {
- // this.data = { ...initData };
- // console.log(initData);
- // createInputs(this.data);
- // cancelCallback();
- // };
- // }
- // this.okCallback = okCallback;
- // this.cancelCallback = cancelCallback;
- // this.data = data;
- // this.validators = {};
- // }
- // let form = new Form(
- // formContainer,
- // {
- // "*name": "Anakin",
- // "*surname": "SkywalkerSkywalkerSkywalkerSkywalkerSkywalkerSkywalkerSkywalkerSkywalker",
- // married: true,
- // birthday: new Date(new Date().getTime() - 86400000 * 30 * 365),
- // },
- // () => console.log("ok"),
- // () => console.log("cancel")
- // );
- // form.okCallback = () => console.log("ok2");
- // form.validators.surname = (value, key, data, input) =>
- // value.length > 2 && value[0].toUpperCase() == value[0] && !value.includes(" ") ? true : "Wrong surname";
- // form.validators["*name"] = (value, key, data, input) =>
- // value.length > 3 && value[0].toUpperCase() == value[0] && !value.includes(" ") ? true : "Wrong name";
- // form.validators["birthday"] = (value, key, data, input) => {
- // if (new Date(value.toISOString().slice(0, 16)) <= new Date("1900-01-01")) {
- // return "Wrong date";
- // }
- // if (
- // new Date(value.toISOString().slice(0, 16)).getTime() >=
- // new Date().getTime() - new Date().getTimezoneOffset() * 1000 * 60 - 3 * 365 * 86400000
- // ) {
- // return "Wrong date";
- // }
- // return true;
- // };
- // console.log(form);
- //POWER OF THE FORM
- // function Password(parent, open) {
- // let formBody = document.createElement("div");
- // let passwordInput1 = document.createElement("input");
- // let passwordInput2 = document.createElement("input");
- // let isOpenInput = document.createElement("input");
- // let checkButton = document.createElement("button");
- // let errorDiv = document.createElement("div");
- // let errors = {
- // blankFields: "Password fields cannot be empty",
- // notMatch: "Password confirmation does not match",
- // };
- // let errorSet = new Set();
- // parent.append(formBody);
- // errorDiv.style.color = "red";
- // checkButton.innerText = "Submit";
- // passwordInput1.type = open ? "text" : "password";
- // passwordInput1.oninput = () => {
- // this.value1 = passwordInput1.value;
- // checkButton.disabled = !isValid();
- // if (typeof this.onPassword1Change === "function") {
- // this.onPassword1Change(this.value1);
- // }
- // };
- // passwordInput2.type = "password";
- // passwordInput2.style.display = !open ? "inline" : "none";
- // passwordInput2.oninput = () => {
- // this.value2 = passwordInput2.value;
- // checkButton.disabled = !isValid();
- // console.log(isValid());
- // if (typeof this.onPassword2Change === "function") {
- // this.onPassword2Change(this.value2);
- // }
- // };
- // isOpenInput.type = "checkbox";
- // isOpenInput.checked = open;
- // isOpenInput.onchange = () => {
- // this.open = isOpenInput.checked;
- // checkButton.disabled = !isValid();
- // passwordInput1.type = this.open ? "text" : "password";
- // passwordInput2.style.display = !this.open ? "inline" : "none";
- // if (typeof this.onOpenChange === "function") {
- // this.onOpenChange(this.open);
- // }
- // };
- // const setValue1 = (newValue) => {
- // this.value1 = newValue;
- // passwordInput1.value = newValue;
- // checkButton.disabled = !isValid();
- // };
- // const setValue2 = (newValue) => {
- // this.value2 = newValue;
- // passwordInput2.value = newValue;
- // checkButton.disabled = !isValid();
- // };
- // const getValue1 = () => {
- // return this.value1;
- // };
- // const getValue2 = () => {
- // return this.value2;
- // };
- // const setOpen = (value) => {
- // this.open = value;
- // isOpenInput.checked = value;
- // passwordInput1.type = this.open ? "text" : "password";
- // passwordInput2.style.display = !this.open ? "inline" : "none";
- // checkButton.disabled = !isValid();
- // };
- // const getOpen = () => {
- // return this.open;
- // };
- // const isValid = () => {
- // if (this.open === true) {
- // return false;
- // }
- // if (this.value1.trim() === "" || this.value2.trim() === "") {
- // errorSet.add(errors.blankFields);
- // showErrors();
- // return false;
- // } else {
- // errorSet.delete(errors.blankFields);
- // }
- // if (this.value1 !== this.value2) {
- // errorSet.add(errors.notMatch);
- // showErrors();
- // return false;
- // } else {
- // errorSet.delete(errors.notMatch);
- // }
- // showErrors();
- // return true;
- // };
- // const showErrors = () => {
- // let str = "";
- // for (let er of errorSet) {
- // str += er + "<br>";
- // }
- // errorDiv.innerHTML = str;
- // };
- // formBody.append(passwordInput1);
- // formBody.append(passwordInput2);
- // formBody.append(isOpenInput);
- // formBody.append(checkButton);
- // formBody.append(errorDiv);
- // this.open = open;
- // this.value1 = passwordInput1.value;
- // this.value2 = passwordInput2.value;
- // this.setOpen = setOpen;
- // this.getOpen = getOpen;
- // this.setValue1 = setValue1;
- // this.getValue1 = getValue1;
- // this.setValue2 = setValue2;
- // this.getValue2 = getValue2;
- // checkButton.disabled = !isValid();
- // }
- // let p = new Password(document.body, true);
- // p.onPassword1Change = (data) => console.log(data);
- // p.onPassword2Change = (data) => console.log(data);
- // p.onOpenChange = (open) => console.log(open);
- // p.setValue1("qwerty");
- // console.log(p.getValue1());
- // p.setValue2("qwer");
- // console.log(p.getValue2());
- // p.setOpen(false);
- // console.log(p.getOpen());
- </script>
- </body>
- </html>
|