Skip to content

Commit

Permalink
Remove default limits for 'Attach' field file size and quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Nov 23, 2024
1 parent 958948d commit e311460
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions resources/js/controllers/attach_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +124,7 @@ export default class extends ApplicationController {

let limit = this.attachmentValue.length < this.countValue;

if (!limit) {
if (!limit && this.countValue > 0) {
return;
}

Expand Down Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions src/Screen/Fields/Attach.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e311460

Please sign in to comment.