-
Notifications
You must be signed in to change notification settings - Fork 7
/
Sidebar.js.html
56 lines (41 loc) · 1.23 KB
/
Sidebar.js.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
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script>
$(document).ready(function() {
$('#test-form').submit(onSidebarFormSubmit)
})
function onSidebarFormSubmit(event) {
event.preventDefault()
var status = $('#submit-status')
var button = $('#submit-button')
var form = $('#test-form').get()[0]
status.hide()
button.text('Submitting...')
button.addClass('disabled')
google.script.run
.withSuccessHandler(function() {
resetForm('Form submitted OK!')
})
.withFailureHandler(function(error) {
resetForm(error, true)
})
.onFormSubmit(form);
// Private Functions
// -----------------
function resetForm(message, isError) {
if (isError) {
status.addClass('error')
} else {
form.reset()
status.removeClass('error')
}
status.text(message)
status.show()
button.text('Submit')
button.removeClass('disabled')
}
}
</script>