jamespickard
jamespickard
FFilament
Created by jamespickard on 9/9/2024 in #❓┊help
Calling refreshFormData on repeater clears them
I have an action that is defined like this:
// app/Filament/Resources/FeedbackResource/Pages/EditFeedback.php
<?php

namespace App\Filament\Resources\FeedbackResource\Pages;

use App\Filament\Resources\FeedbackResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Log;

class EditFeedback extends EditRecord
{
protected static string $resource = FeedbackResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\Action::make('generate-feedback-ai-sentiment-analysis')
->label('AI Sentiment Analysis')
->action(function () {
Log::info("Generating AI Sentiment Analysis for feedback {$this->record->id}...");
$this->record->performSentimentAnalysisUsingAI();
$this->refreshFormData([
'event_names',
'comments',
'party_size',
]);
}),
];
}
}
// app/Filament/Resources/FeedbackResource/Pages/EditFeedback.php
<?php

namespace App\Filament\Resources\FeedbackResource\Pages;

use App\Filament\Resources\FeedbackResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Log;

class EditFeedback extends EditRecord
{
protected static string $resource = FeedbackResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\Action::make('generate-feedback-ai-sentiment-analysis')
->label('AI Sentiment Analysis')
->action(function () {
Log::info("Generating AI Sentiment Analysis for feedback {$this->record->id}...");
$this->record->performSentimentAnalysisUsingAI();
$this->refreshFormData([
'event_names',
'comments',
'party_size',
]);
}),
];
}
}
And a form that's like this:
// app/Filament/Resources/FeedbackResource.php
// ...
class FeedbackResource extends Resource
{
// ...
public static function form(Form $form): Form
{
return $form
->schema([
Repeater::make('event_names')
->simple(
TextInput::make('event_name'),
),
Repeater::make('comments')
->simple(
TextInput::make('comment'),
),
TextInput::make('party_size'),
]);
}
}
// app/Filament/Resources/FeedbackResource.php
// ...
class FeedbackResource extends Resource
{
// ...
public static function form(Form $form): Form
{
return $form
->schema([
Repeater::make('event_names')
->simple(
TextInput::make('event_name'),
),
Repeater::make('comments')
->simple(
TextInput::make('comment'),
),
TextInput::make('party_size'),
]);
}
}
And although the party_size field refreshes property, the event_names and comments fields become blank. Am I doing something wrong? I made an example repository here: https://github.com/cloudshipco/filamentphp-repeater-refresh-bug
10 replies
FFilament
Created by jamespickard on 9/8/2024 in #❓┊help
How to model one-to-many and allow "many" updates inside the "one" form?
I am making an application that allows users to review and update handwritten feedback forms. Each feedback form has one or more comments on it. Presently, I am modelling this as a JSON column - using an array of strings (each string is a comment). I could equally model this using a separate database table. I am looking for advice on the best way to do this so that I can add, edit and remove comments within the feedback form edit screen. I started trying to create a custom ViewField, but I don't know Filament well enough to know whether this approach is likely to work. Those of you more experienced with Filament, how would you do this? I imagine a similar sort issue could come up anywhere you want to edit the "many" in a one-to-many relationship from the "one" screen. For example, adding tags to a post, categories to a product, etc etc.
6 replies
FFilament
Created by jamespickard on 9/7/2024 in #❓┊help
How can I use Filament styles?
Sorry - I just started using Filament today. I want to create a custom blade view for rendering a form component. The field in question is a JSON field that stores an array of strings. I want this rendered as multiple input fields. How can I make it so the input fields match the default Filament styles? Is there a component or partial I can use? Surely I don't just to manually copy all the Tailwind strings from a filament input to match the styling? Here's my code so far:
{{-- filament.forms.components.json-array-as-html-list.blade.php --}}
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>

<div x-data="{ state: $wire.$entangle('data.comments') }")>
<template x-for="(item, idx) in state" :key="idx">
<input x-model="state[idx]" type="text" class="form-input" />
</template>
</div>
</x-dynamic-component>
{{-- filament.forms.components.json-array-as-html-list.blade.php --}}
<x-dynamic-component
:component="$getFieldWrapperView()"
:field="$field"
>

<div x-data="{ state: $wire.$entangle('data.comments') }")>
<template x-for="(item, idx) in state" :key="idx">
<input x-model="state[idx]" type="text" class="form-input" />
</template>
</div>
</x-dynamic-component>
// app/Filament/Resources/FeedbackResource.php
ViewField::make('comments')->view('filament.forms.components.json-array-as-html-list'),
// app/Filament/Resources/FeedbackResource.php
ViewField::make('comments')->view('filament.forms.components.json-array-as-html-list'),
5 replies
FFilament
Created by jamespickard on 9/7/2024 in #❓┊help
Documentation doesn't actually say what the components do
I am just starting out with Filament, reading the documentation, and am a bit confused. When I go to, for example, the Infolist Builder section there is no description of what the component is for, or looks like: https://filamentphp.com/docs/3.x/infolists/installation I would expect that to be the first thing when you click on a component, a description of the component... Maybe an image of the component... Am I missing something?
7 replies