-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_csv2.html
72 lines (64 loc) · 2.39 KB
/
demo_csv2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSV Textarea Example</title>
<script type="module" src="csvtextarea.js"></script>
</head>
<body>
<h1>CSV Textarea Example, with caption</h1>
<p>This demo shows a table with a caption and three rows empty content.</p>
<form id="csv-form" action="/submit" method="POST">
<label for="family-name">Family Name</label> <input type="text" id="family-name" name="family-name" placeholder="enter your family name"><br>
<label for="given-name">Give Name</label> <input type="text" id="given-name" name="given-name" placeholder="enter your given name"><br>
<label for="groups">Enter Groups as CSV Data:</label>
<csv-textarea
id="groups"
name="groups"
cols="2"
maxlength="10"
rows="3"
column-headings="group name,clgid"
caption="Groups List Manager"
>
<textarea id="csvData" name="csvData"></textarea>
</csv-textarea>
<p>
<input type="submit" value="submit">
</form>
<script>
document.getElementById('groups').addEventListener('change', function(event) {
console.log(`DEGUG what is inner text? -> ${this.innerHTML}`);
});
document.getElementById('csv-form').addEventListener('submit', function (event) {
event.preventDefault();
const csvComponent = document.getElementById('groups');
const csvData = csvComponent.innerHTML;
const familyName = document.getElementById('family-name');
const givenName = document.getElementById('given-name');
const formData = new FormData();
formData.set('family-name', familyName.value);
formData.set('given-name', givenName.value);
formData.set('groups', csvData);
fetch('/submit', {
method: 'POST',
body: formData,
})
.then(response => response.text())
.then(result => {
console.log('Success:', result);
})
.catch(error => {
console.error('Error:', error);
});
});
// Example usage
document.querySelector('csv-textarea').closest('form').addEventListener('submit', (event) => document.querySelector('csv-textarea').submitCSVContent(event));
// Add an event listener for the custom 'cell-changed' event
document.querySelector('csv-textarea').addEventListener('cell-changed', (event) => {
console.log('Cell changed:', event.detail);
});
</script>
</body>
</html>