-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_csv3.html
46 lines (45 loc) · 1.39 KB
/
demo_csv3.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSV Textarea Only Example</title>
<p>This implementation should fallback to the innerHTML containing the textarea if JavaScript is disabled.</p>
<script type="module" src="csvtextarea.js" defer></script>
</head>
<body>
<form id="csv-form" action="/submit" method="POST">
<label for="groups">Enter Groups CSV Data:</label>
<csv-textarea
id="groups"
name="groups"
column-headings="group name, group id"
>
<textarea id="groups" name="groups" placeholder="Enter group name, comma and then clgid. One per line."></textarea>
</csv-textarea>
<p></p>
<button type="submit">Submit</button>
</form>
<script>
const csvForm = document.getElementById('csv-form');
csvForm.addEventListener('submit', function (event) {
event.preventDefault();
const csvComponent = document.getElementById('groups');
const csvData = csvComponent.toCSV();
const formData = new FormData();
formData.set('groups', csvData);
fetch(csvForm.action, {
method: csvForm.method,
body: formData,
})
.then(response => response.text())
.then(result => {
console.log('Success:', result);
})
.catch(error => {
console.error('Error:', error);
});
});
</script>
</body>
</html>