Skip to content

Commit 20a2579

Browse files
committed
name of uploaded file in form is now displayed
1 parent 3d64f77 commit 20a2579

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

assets/scss/templates/_main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ body {
1616
input[type="file"] {
1717
display: none;
1818
}
19+
1920
.file-upload {
2021
border: 1px dashed #005AA7;
2122
border-radius: 10px;

layouts/shortcodes/form1.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
{{ $_hugo_config := `{ "version": 1 }` }}
22
{{ with .Page.Params.form1}}
33

4+
<!-- js changing 'Choose file' text to name of uploaded file -->
5+
<script>
6+
function displayFile(ID) {
7+
const fileInput = document.getElementById(ID);
8+
const textArea = fileInput.nextElementSibling;
9+
const file = fileInput.files[0];
10+
textArea.innerText = file.name;
11+
};
12+
</script>
13+
414
<div class="container-fluid p-0" id={{ .id }}>
515
<div class="shadow form-mobile-desktop-layout bg-white rounded-blue-border">
616
<div class="col-lg-12 mb-4">
@@ -40,14 +50,15 @@ <h3 style="color:#005AA7;">
4050

4151
<!-- file upload -->
4252
{{ else if eq .type "file"}}
53+
4354
<!-- title -->
4455
<p class="mb-2" style="color: #005AA7;">{{ .label | markdownify }}{{if .required}}*{{end}}</p>
4556
<!-- upload zone -->
4657
<label style="font-weight:500;" class="file-upload" for="{{.id}}">
47-
<input type="{{.type}}" class="form-control" id="{{.id}}" value="{{.value}}" {{if .required}} required {{end}} name="{{.label}}" placeholder="{{.placeholder}}" />
58+
<input type="{{.type}}" onchange="displayFile({{.id}})" class="form-control" id="{{.id}}" value="{{.value}}" {{if .required}} required {{end}} name="{{.label}}" placeholder="{{.placeholder}}" />
4859
<div style="display:grid; place-items:center;">
4960
<i class="fas fa-upload my-2" style="font-size:24px;"></i>
50-
<p style="color:#005AA7;">{{.file_upload_text}}</p>
61+
<p id="upload-text" style="color:#005AA7;">{{.file_upload_text}}</p>
5162
</div>
5263
</label>
5364

layouts/shortcodes/form2.html

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
{{ $_hugo_config := `{ "version": 1 }` }}
22
{{ with .Page.Params.form2}}
33

4+
<!-- js changing 'Choose file' text to name of uploaded file -->
5+
<script>
6+
function displayFile(ID) {
7+
const fileInput = document.getElementById(ID);
8+
const textArea = fileInput.nextElementSibling;
9+
const file = fileInput.files[0];
10+
textArea.innerText = file.name;
11+
};
12+
</script>
13+
414
<div class="container-fluid p-0" id={{ .id }}>
515
<div class="shadow form-mobile-desktop-layout bg-white rounded-blue-border">
616
<div class="col-lg-12 mb-4">
@@ -26,18 +36,29 @@ <h3 style="color:#005AA7;">
2636

2737
<!-- check boxes -->
2838
{{ else if eq .type "checkbox"}}
29-
<input type="{{.type}}" class="form-control" id="{{.id}}" value="{{.value}}" {{if .required}} required {{end}} name="{{.label}}" placeholder="{{.placeholder}}" />
39+
{{ $input := . }}
40+
<!-- title -->
41+
<p class="mb-4" style="color: #005AA7;">{{ .label | markdownify }}{{if .required}}*{{end}}</p>
42+
<div class="row">
43+
{{ range .values}}
44+
<div class="col form-group">
45+
<input type="{{$input.type}}" class="form-control checkbox" id="{{.id}}" value="{{.value}}" {{if $input.required}} required {{end}} name="{{.label}}" />
46+
<label for="{{.id}}" class="mb-0">{{ .label | markdownify }}{{if .required}}*{{end}}</label>
47+
</div>
48+
{{end}}
49+
</div>
3050

3151
<!-- file upload -->
3252
{{ else if eq .type "file"}}
53+
3354
<!-- title -->
3455
<p class="mb-2" style="color: #005AA7;">{{ .label | markdownify }}{{if .required}}*{{end}}</p>
3556
<!-- upload zone -->
3657
<label style="font-weight:500;" class="file-upload" for="{{.id}}">
37-
<input type="{{.type}}" class="form-control" id="{{.id}}" value="{{.value}}" {{if .required}} required {{end}} name="{{.label}}" placeholder="{{.placeholder}}" />
58+
<input type="{{.type}}" onchange="displayFile({{.id}})" class="form-control" id="{{.id}}" value="{{.value}}" {{if .required}} required {{end}} name="{{.label}}" placeholder="{{.placeholder}}" />
3859
<div style="display:grid; place-items:center;">
3960
<i class="fas fa-upload my-2" style="font-size:24px;"></i>
40-
<p style="color:#005AA7;">{{.file_upload_text}}</p>
61+
<p id="upload-text" style="color:#005AA7;">{{.file_upload_text}}</p>
4162
</div>
4263
</label>
4364

static/js/home_script.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function hasScrolled() {
3434
}
3535

3636
lastScrollTop = st;
37-
}
37+
};
3838

3939
// Why we exist AI Act/DSA/GDPR etc.
4040
$(document).on("click", ".menu2 div", function () {
@@ -168,13 +168,6 @@ $(function () { // wait for document ready
168168
}
169169
});
170170

171-
// Remove preview value from input field
172-
$(document).ready(function () {
173-
$("#mce-EMAIL").click(function(event) {
174-
$(this).attr("placeholder", "");
175-
});
176-
});
177-
178171

179172
// Send subscibtion for newsletter
180173
(function($)

0 commit comments

Comments
 (0)