-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
178 lines (155 loc) · 5.28 KB
/
index.html
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Fields from Google Sheets</title>
<style>
body {
background-color: lightgrey;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
h2 {
color: #333;
}
h4 {
color: #555;
}
#dynamicForm {
background-color: #FAF9F6; /* White background */
padding: 20px;
margin: 0; /* Reset margin to remove default margin */
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
/* Add margin to the formField class to create separation between form fields */
.formField {
margin-bottom: 16px;
}
label {font-weight: bold;
margin-right: 8px;}
</style>
<script src="https://apis.google.com/js/api.js"></script>
</head>
<h1>Create Agreement</h1>
<h2>Supplier Agreement</h2>
<body>
<div id="dynamicFieldsContainer"></div>
<div id="dynamicForm">
<!-- Existing form fields here -->
<!-- Dummy Buttons -->
<div style="margin-bottom: 16px;">
<button type="button" onclick="handlePrevious()">Previous</button>
<button type="button" onclick="handleNext()">Next</button>
<button type="button" onclick="handleSave()">Save</button>
<button type="button" onclick="handleDiscard()">Discard</button>
</div>
</div>
<script>
// Load the Google Sheets API
gapi.load('client', initClient);
// Function to initialize the Google Sheets API client
function initClient() {
gapi.client.init({
apiKey: 'AIzaSyBo4KSquNH5NOdkUUfiIaJe123DkpfP_W8', // Replace with your API key
discoveryDocs: ['https://sheets.googleapis.com/$discovery/rest?version=v4'],
}).then(() => {
handleSheetData();
});
}
function handleSheetData() {
const spreadsheetId = '11sHPQgVOiS32WQpBcQG0q1kLI9LLFBs6pmeIsopAvj0';
const range = 'ContractTypeAttributes';
gapi.client.sheets.spreadsheets.values.get({
spreadsheetId,
range,
}).then(response => {
const data = response.result.values;
if (data) {
const labels = data.map(entry => entry[2]); // Assuming ICMDisplayName is in the first column
const fields = data.map(entry => entry[4]); // Assuming DataType is in the second column
createDynamicForm(labels, fields);
} else {
console.error('No data found in the sheet');
}
});
}
function createDynamicForm(labels, fields) {
const formContainer = document.createElement('div');
formContainer.id = 'dynamicForm';
labels.forEach((label, index) => {
const formField = document.createElement('div');
const labelElement = document.createElement('label');
labelElement.textContent = label;
const input = document.createElement('input');
input.name = label; // You may want to adjust this based on your specific needs
// Map input types based on the values in the 'fields' array
const fieldType = mapFieldType(fields[index]);
if (fieldType) {
input.type = fieldType;
} else {
// Handle the case where the input type is not recognized
console.error('Unrecognized input type for field:', label);
return;
}
// You can set additional attributes or validations based on the fieldType if needed
formField.appendChild(labelElement);
formField.appendChild(input);
formContainer.appendChild(formField);
});
document.getElementById('dynamicFieldsContainer').appendChild(formContainer);
}
// Function to map input types based on the values in the 'fields' array
function mapFieldType(field) {
switch (field) {
case 'Auto':
case 'Label':
case 'Email':
case 'RichTextArea':
case 'String':
return 'text';
case 'Boolean':
return 'checkbox';
case 'Choice':
case 'MultiSelectChoice':
return 'select';
case 'Currency':
case 'Number':
case 'Percentage':
return 'number';
case 'Date':
return 'date';
case 'DateTime':
return 'datetime-local';
case 'FileSelection':
return 'file';
case 'TextArea':
return 'textarea';
case 'URL':
return 'url';
case 'User':
return 'text';
case 'Auto':
return 'text';
default:
return null; // Return null for unrecognized types
}
}
function handlePrevious() {
alert('Previous button clicked!');
}
function handleNext() {
alert('Next button clicked!');
}
function handleSave() {
alert('Save button clicked!');
}
function handleDiscard() {
alert('Discard button clicked!');
}
</script>
<script async defer src="https://apis.google.com/js/api.js"></script>
</body>
</html>