function Form(el, data, okCallback, cancelCallback) { let rootData = { ...data } let formBody = document.createElement('div') let okButton = document.createElement('button') okButton.innerHTML = 'OK' let cancelButton = document.createElement('button') cancelButton.innerHTML = 'Cancel' const table = document.createElement('table') const errorText = document.createElement('span') let input let inputArray = [] for (const [key, value] of Object.entries(data)) { const tr = document.createElement('tr') const th = document.createElement('th') const td = document.createElement('td') key[0] === '*' ? th.innerHTML = `${key[0]} ${key.slice(1)}` : th.innerHTML = key let inputCreators = { String(key, value, oninput) { const input = document.createElement('input') input.type = (/^[*]+$/i).test(value) ? 'password' : 'text' input.placeholder = key input.value = (/^[*]+$/i).test(value) ? '' : value input.oninput = () => { key[0] === '*' && input.value === '' ? input.style.borderColor = 'red' : input.style.borderColor = '' oninput(input.value) } return input }, Boolean(key, value, oninput) { const input = document.createElement('input') input.type = 'checkbox' input.checked = value input.oninput = () => oninput(input.checked) return input }, Date(key, value, oninput) { const input = document.createElement('input') input.type = 'datetime-local' input.oninput = () => oninput(new Date(input.value)) const offset = value.getTimezoneOffset() const now = value.getTime() const nowPlusOffset = new Date(now - offset * 60 * 1000) input.value = nowPlusOffset.toISOString().slice(0, -1) return input }, } input = inputCreators[value.constructor.name](key, value, value => { if (key in this.validators && !this.validators[key](value)) { errorText.innerText = `Please, enter correct ${key}` errorText.classList.add('error'); input.style.borderColor = 'red' td.append(errorText) } else { input.style.color = 'black' errorText.remove() } data[key] = value }) inputArray.push(input) table.append(tr) tr.append(th) tr.append(td) td.append(input) } console.log(inputArray[3].value); formBody.innerHTML = '