123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <head>person Form</head>
- <body>
- <script>
- /*const addElement = (domEl, value, onInputFunc) => {
- const input = document.createElement('input');
- input.value = value;
- input.oninput = onInputFunc;
- domEl.append(input);
- }*/
- const personForm = (domEl, obj) => {
- /*addElement(
- domEl,
- obj.getName(),
- () => {
- obj.setName(nameInput.value);
- fullNameInput.value = obj.getFullName();
- });
- addElement(
- domEl,
- obj.getSurName(),
- () => {
- obj.setSurName(nameInput.value);
- fullNameInput.value = obj.getFullName();
- });
- addElement(
- domEl,
- obj.getFatherName(),
- () => {
- obj.setFatherName(nameInput.value);
- fullNameInput.value = obj.getFullName();
- });
- addElement(
- domEl,
- obj.getAge(),
- () => obj.setAge(ageInput.value));
- addElement(
- domEl,
- obj.getFullName(),
- () => {
- obj.setFullName(fullNameInput.value);
- nameInput.value = obj.getName();
- surNameInput.value = obj.getSurName();
- fatherNameInput.value = obj.getFatherName();
- });*/
- const nameInput = document.createElement('input');
- const surNameInput = document.createElement('input');
- const fatherNameInput = document.createElement('input');
- const ageInput = document.createElement('input');
- const fullNameInput = document.createElement('input');
- domEl.append(nameInput);
- nameInput.value = obj.getName();
- domEl.append(surNameInput);
- surNameInput.value = obj.getSurName();
- domEl.append(fatherNameInput);
- fatherNameInput.value = obj.getFatherName();
- domEl.append(fullNameInput);
- fullNameInput.value = obj.getFullName();
- domEl.append(ageInput);
- ageInput.value = obj.getAge();
- nameInput.oninput = () => {
- obj.setName(nameInput.value);
- fullNameInput.value = obj.getFullName();
- }
- surNameInput.oninput = () => {
- obj.setSurName(surNameInput.value);
- fullNameInput.value = obj.getFullName();
- }
- fatherNameInput.oninput = () => {
- obj.setFatherName(fatherNameInput.value);
- fullNameInput.value = obj.getFullName();
- }
- ageInput.oninput = () => obj.setAge(ageInput.value);
- fullNameInput.oninput = () => {
- obj.setFullName(fullNameInput.value);
- nameInput.value = obj.getName();
- surNameInput.value = obj.getSurName();
- fatherNameInput.value = obj.getFatherName();
- }
- }
- const isUpperCase = (str) => str.toUpperCase() == str;
- let createPersonClosure = function (name, surName) {
- let result = {};
- let age = 17;
- let fatherName = "Пупкович";
- result.getName = () => name;
- result.getSurName = () => surName;
- result.getFullName = function () {
- return `${result.getName()} ${result.getFatherName()} ${result.getSurName()} `;
- }
- result.setFullName = (newFullName) => {
- const arrFullName = newFullName.split(' ');
- result.setFatherName(arrFullName[1]);
- result.setSurName(arrFullName[2]);
- result.setName(arrFullName[0]);
- }
- result.setName = (newName) => {
- if (isUpperCase(newName[0])) {
- name = newName;
- }
- else
- alert("wrong Name format");
- }
- result.setSurName = (newSurName) => {
- if (isUpperCase(newSurName[0])) {
- surName = newSurName;
- }
- else
- alert("wrong Surname format");
- }
- result.setFatherName = (newFatherName) => {
- if (isUpperCase(newFatherName[0])) {
- fatherName = newFatherName;
- }
- else
- alert("wrong Fathername format");
- }
- result.getAge = () => age;
- result.setAge = (newAge) => {
- if (newAge >= 0 && newAge <= 100)
- age = newAge;
- else
- alert("wrong age: " + newAge);
- }
- result.getFatherName = () => fatherName;
- return result;
- }
- const person = createPersonClosure("Анна", "Иванова");
- personForm(document.body, person);
- </script>
- </body>
|