From be6659b18354ce342a398240a5a0281510e8bf61 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sat, 7 May 2016 21:58:41 -0400 Subject: [PATCH] Disable button when max attachments reached --- inc/view_attachment_functions.inc.php | 17 +++++++++++++++++ index.php | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/inc/view_attachment_functions.inc.php b/inc/view_attachment_functions.inc.php index 6bdc230b..c8f4eed3 100644 --- a/inc/view_attachment_functions.inc.php +++ b/inc/view_attachment_functions.inc.php @@ -229,9 +229,26 @@ function display_dropzone_field($url, $id = 'filedrop') { // Add the database id to the file file['databaseId'] = response; }); + this.on('addedfile', function() { + var numberOfFiles = $('#" . $id . " .file-row').length; + + var disabled = false; + if (numberOfFiles >= " . $max_files . ") { + disabled = true; + } + $('." . $id . "-button').attr('disabled', disabled); + }); this.on('removedfile', function(file) { // Remove the attachment from the database and the filesystem. removeAttachment(file['databaseId']); + + var numberOfFiles = $('#" . $id . " .file-row').length; + + var disabled = false; + if (numberOfFiles >= " . $max_files . ") { + disabled = true; + } + $('." . $id . "-button').attr('disabled', disabled); }); this.on('complete', function(file) { // Stop animating if complete. diff --git a/index.php b/index.php index 59ec77c5..535325b1 100644 --- a/index.php +++ b/index.php @@ -990,7 +990,7 @@ function print_add_ticket() ?> -
+