-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfieldsBackup.js
51 lines (42 loc) · 1.43 KB
/
fieldsBackup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const createSection = (section) => {
let container = document.createElement('div');
container.setAttribute('class', 'section');
section.fields.forEach((field) => {
if (field.type === 'text') {
container.appendChild(createTextField(field));
} else {
container.appendChild(createProductField(field));
}
});
document.querySelector('#form-wrapper').appendChild(container);
};
const createTextField = (textField, onChange) => {
let inpTxtBox = document.createElement('div');
let labelTxt = document.createElement('label');
let inputTxt = document.createElement('input');
labelTxt.innerText = textField.label;
inputTxt.id = textField.id;
inputTxt.type = textField.type;
inpTxtBox.appendChild(labelTxt);
inpTxtBox.appendChild(inputTxt);
return inpTxtBox;
};
const createProductField = (product, onClick) => {
let productBox = document.createElement('div');
let checkBox = document.createElement('input');
let productPrice = document.createElement('div');
let productTitle = document.createElement('div');
checkBox.type = 'checkbox';
checkBox.id = product.id;
productPrice.innerText = product.price + '€';
productTitle.innerText = product.title;
productBox.appendChild(checkBox);
productBox.appendChild(productTitle);
productBox.appendChild(productPrice);
return productBox;
};
export const fieldsMap = {
section: createSection,
text: createTextField,
product: createProductField,
};