feat: Add clear button for file upload input in posting_attach.tpl (#2072)

This commit is contained in:
Roman Kelesidis 2025-08-03 18:48:17 +03:00 committed by GitHub
commit 7c6ab0eed4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,8 @@
<!-- IF TPL_ADD_ATTACHMENT --> <!-- IF TPL_ADD_ATTACHMENT -->
<!--========================================================================--> <!--========================================================================-->
<style>#clear_file_upload { display: none; }</style>
<tr> <tr>
<th colspan="2" class="thHead">{L_ADD_ATTACHMENT_TITLE}</th> <th colspan="2" class="thHead">{L_ADD_ATTACHMENT_TITLE}</th>
</tr> </tr>
@ -10,6 +12,7 @@
<table class="borderless" cellspacing="0"> <table class="borderless" cellspacing="0">
<tr> <tr>
<td class="pad_4"> <td class="pad_4">
<input type="button" id="clear_file_upload" value="{L_CLEAR}" />
<input type="file" name="fileupload" size="45" maxlength="{FILESIZE}" /> <input type="file" name="fileupload" size="45" maxlength="{FILESIZE}" />
<p class="small nowrap">{L_ADD_ATTACHMENT_EXPLAIN}</p> <p class="small nowrap">{L_ADD_ATTACHMENT_EXPLAIN}</p>
</td> </td>
@ -26,6 +29,24 @@
</td> </td>
</tr> </tr>
<script type="text/javascript">
$(document).ready(function () {
$('input[name="fileupload"]').on('change', function () {
if (this.files && this.files.length > 0) {
$('input[type=button]#clear_file_upload').show();
} else {
$('input[type=button]#clear_file_upload').hide();
}
});
$('input[type=button]#clear_file_upload').on('click', function () {
$('input[name="filecomment"]').val('');
$('input[name="fileupload"]').val('');
$('input[type=button]#clear_file_upload').hide();
});
});
</script>
<!--========================================================================--> <!--========================================================================-->
<!-- ENDIF / TPL_ADD_ATTACHMENT --> <!-- ENDIF / TPL_ADD_ATTACHMENT -->