filament-comments icon indicating copy to clipboard operation
filament-comments copied to clipboard

Hide form option

Open pelmered opened this issue 2 years ago • 0 comments

Like I wrote about in issue #7, I wanted to have the form only in a modal and display the comments in an infolist. I think this UX works better as the infolist should be view/read only and I want it as compact as possible to avoid scrolling.

This is a working example with the modal as a headerAction on a section:

                    Section::make('Admin comments')
                           ->headerActions([
                               Action::make('Add comment')
                                     ->form(function (Form $form, Booking $booking) {
                                         $comments = new CommentsComponent();
                                         $comments->record = $booking;
                                         return $comments->form($form);
                                     })
                                     ->action(function (array $data, Booking $booking): void {
                                         CommentsComponent::macro('fillForm', function ($data) {
                                            $this->form->fill($data);
                                         });
                                         $comments = new CommentsComponent();
                                         $comments->record = $booking;
                                         $comments->fillForm($data);
                                         $comments->create();
                                     })
                               ])
                           ->columnSpanFull()
                           ->schema([
                               CommentsEntry::make('filament_comments')->withoutForm(),
                           ]),

It looks like this: Screenshot by Dropbox Capture

Possible enhancements:

  • The comments list does not refresh when you submit a new comment in the modal. You need to refresh the page for the new comment to show up.
  • Split the form into it's own component to make this even easier/cleaner to do. It would also be nice with an action that you can use directly, or even a method that returns this whole section.

pelmered avatar Mar 01 '24 10:03 pelmered