Skip to content

Commit

Permalink
fix: File upload compact circle error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Aug 15, 2024
1 parent c87823a commit 747f3a9
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 66 deletions.

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions docs-assets/app/public/js/filament/forms/components/file-upload.js

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions docs-assets/app/public/js/filament/forms/components/rich-editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/forms/dist/components/file-upload.js

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions packages/forms/dist/components/rich-editor.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions packages/forms/resources/js/components/file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export default function fileUploadFormComponent({

lastState: null,

error: null,

uploadedFileIndex: {},

isEditorOpen: false,
Expand Down Expand Up @@ -313,6 +315,21 @@ export default function fileUploadFormComponent({
this.pond.on('processfileabort', handleFileProcessing)

this.pond.on('processfilerevert', handleFileProcessing)

if (panelLayout === 'compact circle') {
// The compact circle layout does not have enough space to render an error message inside the input.
// As such, we need to display the error message outside of the input, using the `error` Alpine.js
// property that is output as a message in the field's view.

this.pond.on('error', (error) => {
// FilePond has a weird English translation for the error message when a file of an unexpected
// type is uploaded, for example: `File of invalid type: Expects or image/*`. This is a
// hacky workaround to fix the message to be `File of invalid type: Expects image/*`.
this.error = `${error.main}: ${error.sub}`.replace('Expects or', 'Expects')
})

this.pond.on('removefile', () => this.error = null)
}
},

destroy: function () {
Expand Down
18 changes: 11 additions & 7 deletions packages/forms/resources/views/components/file-upload.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,11 @@
->merge($getExtraAttributes(), escape: false)
->merge($getExtraAlpineAttributes(), escape: false)
->class([
'fi-fo-file-upload flex [&_.filepond--root]:font-sans',
'fi-fo-file-upload flex flex-col gap-y-2 [&_.filepond--root]:font-sans',
match ($alignment) {
Alignment::Start => 'justify-start',
Alignment::Center => 'justify-center',
Alignment::End => 'justify-end',
Alignment::Left => 'justify-left',
Alignment::Right => 'justify-right',
Alignment::Between, Alignment::Justify => 'justify-between',
Alignment::Start, Alignment::Left => 'items-start',
Alignment::Center => 'items-center',
Alignment::End, Alignment::Right => 'items-end',
default => $alignment,
},
])
Expand All @@ -142,6 +139,13 @@
/>
</div>

<div
x-show="error"
x-text="error"
x-cloak
class="text-sm text-danger-600 dark:text-danger-400"
></div>

@if ($hasImageEditor && (! $isDisabled))
<div
x-show="isEditorOpen"
Expand Down

0 comments on commit 747f3a9

Please sign in to comment.