From e31146059bc739f5a9c214bb2122ee1bd9515af4 Mon Sep 17 00:00:00 2001 From: Alexandr Chernyaev Date: Sat, 23 Nov 2024 05:27:12 +0300 Subject: [PATCH] Remove default limits for 'Attach' field file size and quantity --- resources/js/controllers/attach_controller.js | 13 +++++++------ src/Screen/Fields/Attach.php | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/resources/js/controllers/attach_controller.js b/resources/js/controllers/attach_controller.js index bfb5aa525..0e2637ea0 100644 --- a/resources/js/controllers/attach_controller.js +++ b/resources/js/controllers/attach_controller.js @@ -25,11 +25,11 @@ export default class extends ApplicationController { }, count: { type: Number, - default: 3, + default: 0, }, size: { type: Number, - default: 10, + default: 0, }, loading: { type: Number, @@ -86,7 +86,7 @@ export default class extends ApplicationController { [...event.target.files].forEach((file) => { let sizeMB = file.size / 1000 / 1000; //MB (Not MiB) - if (sizeMB > this.sizeValue) { + if (this.sizeValue > 0 && sizeMB > this.sizeValue) { this.toast(this.errorSizeValue.replace(':name', file.name)); //alert(this.errorSizeValue.replace(':name', file.name)); return; @@ -124,7 +124,7 @@ export default class extends ApplicationController { let limit = this.attachmentValue.length < this.countValue; - if (!limit) { + if (!limit && this.countValue > 0) { return; } @@ -159,9 +159,10 @@ export default class extends ApplicationController { * */ togglePlaceholderShow() { - this.containerTarget.classList.toggle('d-none', this.attachmentValue.length >= this.countValue); - this.filesTarget.disabled = this.attachmentValue.length >= this.countValue; + let toggle = this.attachmentValue.length >= this.countValue && this.countValue !== 0; + this.containerTarget.classList.toggle('d-none', toggle); + this.filesTarget.disabled = toggle; // Disable the nullable field if there is at least one valid value and the count equals 1. // If there are no values or if there are multiple values, the field will remain enabled and be sent to the server as `null`. diff --git a/src/Screen/Fields/Attach.php b/src/Screen/Fields/Attach.php index c9d3c1fff..3e39d3e29 100644 --- a/src/Screen/Fields/Attach.php +++ b/src/Screen/Fields/Attach.php @@ -46,8 +46,8 @@ class Attach extends Field * @var array */ protected $attributes = [ - 'maxCount' => 999, - 'maxSize' => 8, // MB + 'maxCount' => 0, + 'maxSize' => 0, // MB 'accept' => '*/*', 'placeholder' => 'Upload file', 'errorMaxSizeMessage' => 'File ":name" is too large to upload',