File size: 3,862 Bytes
a964b2a |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Viewer</title>
</head>
<body>
<div id="form-container"></div>
<script>
// Пример JSON-файла
const formJson = {
"components": [
{
"text": "# File an Invoice\n\nAdd your invoice details below.",
"type": "text",
"id": "Field_1na090z",
"layout": {
"row": "Row_0lmsy15"
}
},
{
"label": "Image view",
"type": "image",
"layout": {
"row": "Row_1ju954r",
"columns": null
},
"id": "Field_0kfhe9d",
"source": "https://i.ibb.co/NrZMfsR/105.png"
},
{
"key": "creditor",
"label": "Creditor",
"type": "textfield",
"validate": {
"required": true
},
"id": "Field_12chft0",
"layout": {
"row": "Row_1rvpcsw"
}
},
{
"description": "An invoice number in the format: C-123.",
"key": "invoiceNumber",
"label": "Invoice Number",
"type": "textfield",
"validate": {
"pattern": "^C-[0-9]+$"
},
"id": "Field_0jcge34",
"layout": {
"row": "Row_0960rdj"
}
},
{
"values": [
{
"label": "Value",
"value": "value"
}
],
"label": "Tag list",
"type": "taglist",
"layout": {
"row": "Row_1szoxy7",
"columns": null
},
"id": "Field_0mea1nt",
"key": "taglist_30y47"
},
{
"values": [
{
"label": "Value",
"value": "value"
}
],
"label": "Checkbox group",
"type": "checklist",
"layout": {
"row": "Row_1szoxy7",
"columns": null
},
"id": "Field_0u7r33p",
"key": "checklist_vyc3y"
},
{
"action": "submit",
"key": "submit",
"label": "Submit",
"type": "button",
"id": "Field_0ie528a",
"layout": {
"row": "Row_1szoxy7"
}
}
],
"schemaVersion": 16,
"exporter": {
"name": "form-js (https://demo.bpmn.io)",
"version": "1.8.3"
},
"type": "default",
"id": "Form_020yixm"
};
// Функция для генерации HTML-формы
function generateForm(formData) {
const container = document.getElementById('form-container');
formData.components.forEach(component => {
const element = document.createElement('div');
element.id = component.id;
if (component.type === 'text') {
element.innerHTML = `<p>${component.text}</p>`;
} else if (component.type === 'textfield') {
element.innerHTML = `<label for="${component.key}">${component.label}</label>
<input type="text" id="${component.key}" name="${component.key}" ${component.validate.required ? 'required' : ''}>`;
} else if (component.type === 'checklist') {
element.innerHTML = `<label>${component.label}</label>`;
component.values.forEach(value => {
element.innerHTML += `<input type="checkbox" id="${value.value}" name="${value.value}" value="${value.value}">
<label for="${value.value}">${value.label}</label>`;
});
} else if (component.type === 'button') {
element.innerHTML = `<button type="button" id="${component.key}">${component.label}</button>`;
}
container.appendChild(element);
});
}
// Генерация формы
generateForm(formJson);
</script>
</body>
</html> |