-
Notifications
You must be signed in to change notification settings - Fork 9
/
filepond.htm
49 lines (42 loc) · 1.51 KB
/
filepond.htm
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
{% if __SELF__.property('uploader_enable') == 1 %}
<link href="https://unpkg.com/filepond/dist/filepond.css" rel="stylesheet">
<script src="https://unpkg.com/filepond-plugin-file-validate-size/dist/filepond-plugin-file-validate-size.js"></script>
<script src="https://unpkg.com/filepond/dist/filepond.js"></script>
<script>
const inputElement = document.querySelector('input[type="file"]');
FilePond.registerPlugin(FilePondPluginFileValidateSize);
const pond = FilePond.create(inputElement, {
onaddfilestart: (file) => { isLoadingCheck(); },
onprocessfile: (files) => { isLoadingCheck(); },
onremovefile: (files) => { isLoadingCheck(); },
onupdatefiles: (files) => { isLoadingCheck(); },
allowFileSizeValidation: true,
maxFileSize: '{{ allowed_filesize }}KB',
});
FilePond.setOptions({
name: 'files[]',
server: {
url: '/martin/forms',
process: '/process',
revert: '/process',
headers: {
'X-CSRF-TOKEN': '{{ form_token() }}',
'FILEPOND-FIELD': pond.name
}
}
});
function isLoadingCheck() {
const isLoading = pond.getFiles().filter(x => x.status !== 5).length !== 0;
if (isLoading) {
$('form [type="submit"]').attr("disabled", "disabled");
} else {
$('form [type="submit"]').removeAttr("disabled");
}
}
</script>
<style>
.filepond--root {
font-size: 1.2rem;
}
</style>
{% endif %}