CGM
CGM
FFilament
Created by CGM on 7/11/2024 in #❓┊help
Hook for FileUpload field when file removed? (X Clicked to remove)
I have the following field:
FileUpload::make('logo')
->disk('tenant_logos')
->afterStateUpdated(function ($state) {
// Do stuff here...
})
->maxSize(12288)
->visibility('public')
->image()
->imageEditor(),
FileUpload::make('logo')
->disk('tenant_logos')
->afterStateUpdated(function ($state) {
// Do stuff here...
})
->maxSize(12288)
->visibility('public')
->image()
->imageEditor(),
It works when expected when uploading an image as ->afterStateUpdated() is fired, however when I click the (X) to remove the photo the ->afterStateUpdated() does not fire. Is there something I'm missing, or is there another hook I can use to run code when the image/upload is removed?
15 replies
FFilament
Created by CGM on 7/10/2024 in #❓┊help
In a test, should fillForm() be firing afterStateUpdated()?
I have the following field:
ColorPicker::make('primary_color')
->live()
->afterStateUpdated(function ($state) {
$this->dispatch('applyThemeColors', [
'primary_color' => $state,
]);
})
->hex()
->hexColor()
->nullable()
->helperText('Leave blank to use default colors'),
ColorPicker::make('primary_color')
->live()
->afterStateUpdated(function ($state) {
$this->dispatch('applyThemeColors', [
'primary_color' => $state,
]);
})
->hex()
->hexColor()
->nullable()
->helperText('Leave blank to use default colors'),
and the following test:
$component = livewire(BrandingSettings::class, ['location' => null])
->assertSuccessful()
->fillForm(['primary_color' => '#007bff'])
->assertDispatched('applyThemeColors');
$component = livewire(BrandingSettings::class, ['location' => null])
->assertSuccessful()
->fillForm(['primary_color' => '#007bff'])
->assertDispatched('applyThemeColors');
On the live site it all works, I assumed this test would have picked it up, however it doesn't. I'm just wondering is there something I need to do in my test to ensure the afterStateUpdated() is fired? The field is set to live().
7 replies
FFilament
Created by CGM on 7/2/2024 in #❓┊help
Adding 'confirmation modal' to a checkbox?
I feel like I'm missing something simple in the docs in regards to action modals. Is there a way to add a 'are you sure you want to toggle this checkbox' style of modal to a checkbox field? Something that would pop up with a confirmation before ->updateStateUsing() is called? I'm using a table builder checkbox colum
11 replies
FFilament
Created by CGM on 6/27/2024 in #❓┊help
Prefill Resource Create Fields from beforeFill()?
I'm looking to prefill some resource fields (when Creating a resource) using values from a cookie. Is the beforeFill() Life Cycle hook an appropriate place to do this? If so, how do I actually interact with the $form from inside this hook? Is there another more appropriate place to do this?
9 replies
FFilament
Created by CGM on 6/25/2024 in #❓┊help
Where to put custom logic shared across multiple Resource classes
Just looking for some guidance on where might be the most appropriate place to put logic that I'm looking to share across multiple Resource classes. My auth logic for some of the action buttons (to hide/show them) is getting a little long and I don't like having the same code in 8 different places. Where might be the best place to put this custom logic? Is there a 'filament way' or am I better off creating a new trait?
4 replies
FFilament
Created by CGM on 6/24/2024 in #❓┊help
How do I test MorphToSelect fields in forms?
I'm trying to write a test to ensure my MorphToSelect field is ->required(), but it is not behaving as I would expect. Are you all aware of any examples of testing the MorphToSelect field in custom forms, or even in panel forms? Here is the field for reference: Here is the example field for reference:
MorphToSelect::make('followup')
->required()
->types([
MorphToSelect\Type::make(CustomMessage::class)
->getOptionLabelFromRecordUsing(fn (CustomMessage $record): string => "{$record->name}")
->titleAttribute('name'),
MorphToSelect\Type::make(Redirect::class)
->getOptionLabelFromRecordUsing(fn (Redirect $record): string => "{$record->name}")
->titleAttribute('name'),
])
MorphToSelect::make('followup')
->required()
->types([
MorphToSelect\Type::make(CustomMessage::class)
->getOptionLabelFromRecordUsing(fn (CustomMessage $record): string => "{$record->name}")
->titleAttribute('name'),
MorphToSelect\Type::make(Redirect::class)
->getOptionLabelFromRecordUsing(fn (Redirect $record): string => "{$record->name}")
->titleAttribute('name'),
])
3 replies
FFilament
Created by CGM on 6/24/2024 in #❓┊help
Testing select list values
Is there a way, other than looking for strings in HTML, to test if a specific value is visible or not visible in a form fields select list?
4 replies
FFilament
Created by CGM on 6/21/2024 in #❓┊help
Changing the MorphToSelect Placeholder
Is there a way to change the MorphToSelect placeholder? I get this error when using ->placeholder() Method Filament\Forms\Components\MorphToSelect::placeholder does not exist. I'm looking to change the text that reads "Select an option" for the initial 'type' selection.
2 replies
FFilament
Created by CGM on 6/19/2024 in #❓┊help
How can I use @error blade directives in my custom form field blade files?
I know it's me missing something obvious, but I'm struggling to properly use @error() @enderror in my custom fields blade file. What goes inside of @error(<here>)? I attempted source diving and found $errors->has($statePath) but this gives me an error: array_key_exists(): Argument #1 ($key) must be a valid array offset type when I try to use it in my own blade template. This is a field created using artisan make:form-field, so nothing too special I don't think.
3 replies
FFilament
Created by CGM on 5/27/2024 in #❓┊help
How to test pages that extend extend ManageRelatedRecords (Create via Modal)
How would you properly setup a simple test for a custom page that extends ManageRelatedRecords? This is a standard page create using make:filament-page and selecting Relationship. The form is in a Modal and I think that is where I'm getting stuck. I would love to see an example of how to just see how to assert the successful submission of a create form (no errors) via the modal. I think I could plow through the rest from there. 🙂
8 replies
FFilament
Created by CGM on 5/17/2024 in #❓┊help
How do I pass values through a render hook?
I have the following hook for my EditUser::class
->renderHook(
PanelsRenderHook::CONTENT_END,
fn (): View => view('components.tenant.roles.role-editor'),
[EditUser::class],
)
->renderHook(
PanelsRenderHook::CONTENT_END,
fn (): View => view('components.tenant.roles.role-editor'),
[EditUser::class],
)
but the view takes a prop of @props(['userId']) how do I get this from my EditUser::class and into the view?
7 replies
FFilament
Created by CGM on 5/17/2024 in #❓┊help
Adding Livewire Component to Sidebar
If I wanted to add a custom livewire component to the sidebar, above or below the standard navigation, where would I start that journey? Is there a nav hook, or a template I can override?
8 replies
FFilament
Created by CGM on 5/16/2024 in #❓┊help
Moving Sub-Navigation Elements to Main Sidebar as Child Elements
No description
11 replies
FFilament
Created by CGM on 5/5/2024 in #❓┊help
How do I refresh my table when I interact with a ToggleColumn?
Is there an easy way to make ToggleColumn::make() reactive, or to get it to refresh the entire table after being toggled? I have other columns that depend on the state of these toggles, but I can't get the updates to the browser without refreshing the page manually. I've tried things like $this->dispatch('$refresh') from different column callbacks, etc but without any luck. Adding <button wire:click="$refresh">Refresh component</button> to a button works, but I want the table to refresh when the toggle is toggled.
ToggleColumn::make('roles.role_full_access')
->afterStateUpdated(function ($state, $record) {
$this->dispatch('$refresh'); // Doesn't cause table refresh
})
ToggleColumn::make('roles.role_full_access')
->afterStateUpdated(function ($state, $record) {
$this->dispatch('$refresh'); // Doesn't cause table refresh
})
7 replies
FFilament
Created by CGM on 3/15/2024 in #❓┊help
Testing Form Wizards
I'm attempting to test a form wizard's->beforeValidation() call (as part of Wizard\Step) in a test, but I don't know how to 'forward' the wizard to the correct step. Is there a way to move a test forward to 'step 2' in a unit test so I can test functions like ->afterValidation() and ->beforeValidation()? I can't seem to get code in those methods to fire at all during tests.
2 replies
FFilament
Created by CGM on 2/27/2024 in #❓┊help
Base design for 'make:livewire-form' forms?
Is it possible to use the base theme from the filament panels on custom forms created using php make:livewire-form?
9 replies
FFilament
Created by CGM on 10/26/2023 in #❓┊help
How do I prevent JSON fields from being blown away when using dot notation on TextInputs?
What I'm trying to do: I'm trying to store data into a JSON field using a TextInput while using dot notation. Forms\Components\TextInput::make('additional.industry') additional is my JSON field, industry is the key in that field I'm editing. My Issue My JSON field has data other than just the 'industry' key, and it is being set elsewhere. When I save submit the Filament form, additional.industry saves what I'm expecting, however every other JSON key is blown away. Example: JSON field before saving: {"other": "other data here", "industry": "service"} JSON field after saving {"industry": "service"} Question How do I preserve the rest of the JSON structure when saving while using dot notation for a TextInput field?
9 replies