Wirkhof
Wirkhof
Explore posts from servers
FFilament
Created by Wirkhof on 4/26/2024 in #❓┊help
How to allow HTML in Placeholder in Form?
My current code is this:
Placeholder::make('custom_placeholder')
->live()
->content(function (Get $get): string {
$html_code = '<div style="background-color: red;">' . $get('updated_at') . '</div>';
return new HtmlString($html_code);
})
->label(__('My placeholder')),
Placeholder::make('custom_placeholder')
->live()
->content(function (Get $get): string {
$html_code = '<div style="background-color: red;">' . $get('updated_at') . '</div>';
return new HtmlString($html_code);
})
->label(__('My placeholder')),
But the output is escaped so I see <div. .. instead of just the red date. How to make HTML work with placeholder in form?
4 replies
FFilament
Created by Wirkhof on 4/26/2024 in #❓┊help
Is there a plan to integrate a mechanism to reflect saved changes for Cancel button in the SPA mode?
Let's say I am editting things in form and save them. Then I click the cancel button next to the save button. I will be redirected/taken back to the listing page where the pagination and filters are still in place - which is nice. What is not nice thought, is the fact that the things I saved in the form are not refreshed with the new values and I have to manually refresh the page. Are there plans to include this functionality by default in Filament? I guess it works like that in non-SPA mode but in SPA mode the data in the list view are stale.
2 replies
FFilament
Created by Wirkhof on 4/22/2024 in #❓┊help
Carbrand::all()->pluck('carbrand_name', 'id') is causing incorrect integer value: '"2"' error
I have this in my select box in Form:
Select::make('carbrand')
->label('Car Brand')
->required()
->options(Carbrand::all()->pluck('carbrand_name', 'id'))
Select::make('carbrand')
->label('Car Brand')
->required()
->options(Carbrand::all()->pluck('carbrand_name', 'id'))
in the Form for create resource is causing this error on Save:
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '"5"' for column 'carbrand' at row 1
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '"5"' for column 'carbrand' at row 1
I guess it is trying to save a string instead of integer - which the column in migration is saved to. How to force Filament to convert the id to integer when saving? Is there any other way to do it without pluck?
4 replies
FFilament
Created by Wirkhof on 4/18/2024 in #❓┊help
Unable to set checkbox default value to true
I have this but it's unchecked:
Forms\Components\Checkbox::make('is_admin')
->inline(true)
->default(true)
Forms\Components\Checkbox::make('is_admin')
->inline(true)
->default(true)
It's unchecked. How to make it checked by default?
5 replies
FFilament
Created by Wirkhof on 4/15/2024 in #❓┊help
How to bring current record into canAccess() method code?
I managed to restrict the access to the edit user page with this code:
public static function canAccess(array $parameters = []): bool
{
return auth()->user()->id == 42;
}
public static function canAccess(array $parameters = []): bool
{
return auth()->user()->id == 42;
}
and it works. However, I need a bit more custom logic that uses some values from the record I am trying to access. And I am unable to use $this->getRecord() inside the code like:
public static function canAccess(array $parameters = []): bool
{
$currentRecord = $this->getRecord();
return auth()->user()->id == 42;
}
public static function canAccess(array $parameters = []): bool
{
$currentRecord = $this->getRecord();
return auth()->user()->id == 42;
}
I am getting this error: Using $this when not in object context Any idea how to access the record inside canAccess() method?
6 replies
FFilament
Created by Wirkhof on 4/15/2024 in #❓┊help
Redirect when entering a certain edit page in resource
I would like to know where in the resource file or edit page should I put a condition and what is the way to do it. I need to check if the user can edit some record based on the record category. I know how to hide the edit button, but the user can enter the id of the record manually in the url and edit it anyway. My guess is it should be put in the Edit page of the resource. But not sure how it should be done. For simplicity, let's say we want to redirect user back to the listing or homepage when his id is 42. How to do that?
33 replies
FFilament
Created by Wirkhof on 4/8/2024 in #❓┊help
How to get panel id name?
How do I get it in the middle of a form or table or wherever? I mean the example.com/>>>adminaltered<<</ part for your admin/panel. I want to change it dynamically and not hardcode it in the prefix in the textfield. That's why I am asking.
6 replies
FFilament
Created by Wirkhof on 3/22/2024 in #❓┊help
How to make the Save button not include custom form field in the saving process?
I have a separate "save" feature included in my custom code that is independent on the Save of the form. It works great. I do what I want via wire:click, stuff is saved directly in the DB as I need. When I leave the form and go to other parts of Admin panel, things are persisted in the DB without the need of pressing the Save button for this record. Now, the problem arises when I am editing the record and press the Save button (the one for the whole form). It messes up the saving of the custom form field. Not sure what it does, probably grabs some wrong values because of bad/stale wire:key or something... the point is that: I do NOT want the Save button to save things in the db for this custom field. I want to exclude this field from being saved with the Save button. I set ->dehydrate(false) on my custom form field and it seems to be working as long as I press the Save button. Then it saves weird things in that DB column. If I remove ->dehydrate(false) or just leave ->dehydrate() I will get the Column not found SQL error. How to make Save ignore this custom field when updating/saving post?
59 replies
FFilament
Created by Wirkhof on 3/21/2024 in #❓┊help
Why isn't Tailwind work in Filament custom component view files?
This is my tailwind config file:
content: [
"./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php",
"./storage/framework/views/*.php",
"./resources/views/**/*.blade.php",
"./app/Livewire/**/*.php",
"./app/Filament/**/*.php",
"./app/Filament/**/*.blade.php",
],
content: [
"./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php",
"./storage/framework/views/*.php",
"./resources/views/**/*.blade.php",
"./app/Livewire/**/*.php",
"./app/Filament/**/*.php",
"./app/Filament/**/*.blade.php",
],
? Normal blade files interpret everythign live as I change it. For example, in any liveview full compoenent when I do bg-fuchsia-500 it works but not in custom component files of Filament that have been generated to /resources/views/forms/components/mycomponent.blade.php How to make it that Tailwind generates css from those clases when using npm run dev the same way as it's doing right now for normal liveview components outside of Filament?
3 replies
FFilament
Created by Wirkhof on 3/20/2024 in #❓┊help
$wire.$refresh() doesn't work
I want to do something like this:
@click="$wire.doSomethingHere(), $wire.$refresh()"
@click="$wire.doSomethingHere(), $wire.$refresh()"
The first doSomethingHere() will run ok, but $wire.$refresh() don't . How to make $wire.$refresh() work?
203 replies
FFilament
Created by Wirkhof on 3/20/2024 in #❓┊help
How to add a custom id or class to an Action button?
I need to add some ids to differentiate my custom action buttons on the edit page.
Action::make('custombutton')
->id('customid')
Action::make('custombutton')
->id('customid')
doesn't work. I am getting:
Method Filament\Actions\Action::id does not exist.
Method Filament\Actions\Action::id does not exist.
How to add a custom id or class to a button?
5 replies
FFilament
Created by Wirkhof on 3/20/2024 in #❓┊help
How to add a method to a custom component?
Currently I am getting this error:
Unable to call component method. Public method [saveCarState] not found on component
Unable to call component method. Public method [saveCarState] not found on component
when I try to run a custom method called saveCarState when clicking on a button like:
<button wire:click="saveCarState">....
<button wire:click="saveCarState">....
I have followed this: https://filamentphp.com/docs/3.x/forms/fields/custom and created the custom component files (component class file and blade view class) via this command:
php artisan make:form-field CarStateSelector
php artisan make:form-field CarStateSelector
I can do the blade view and create bells and whistles. But, in this custom component, I would like to bypass the form actions Save, Cancel, etc. and trigger my own Livewire functions. So, I added `wire:click="saveCarState" on one of my buttons. And I expect that when the user clicks on this button the function saveCarState in the file (that was created by the artisan command):
app/Forms/Components/CarStateSelector.php
app/Forms/Components/CarStateSelector.php
will be triggered. So, I added it there like:
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Field;

class CarStateSelector extends Field
{
protected string $view = 'forms.components.car-state-selector';

public function saveCarState()
{
dd('hello from save');
}
}
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Field;

class CarStateSelector extends Field
{
protected string $view = 'forms.components.car-state-selector';

public function saveCarState()
{
dd('hello from save');
}
}
But I am getting the error message as I said in the beginning. How can I use Livewire method in my custom component? Clearly I am doing something wrong here 😭
9 replies
FFilament
Created by Wirkhof on 3/15/2024 in #❓┊help
How to access $form in Forms?
This code is not working:
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('customstuff')
->action(function ($form) {
dd($form); // doesn't work; returns null
})
]),
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('customstuff')
->action(function ($form) {
dd($form); // doesn't work; returns null
})
]),
I want to be able to access stuff like $form->getRecord()->id in action(). How to do that?
4 replies
FFilament
Created by Wirkhof on 3/15/2024 in #❓┊help
How to find out currently checked Checklist boxes?
EDIT FROM THE FUTURE: In retrospect this is related to the inconsistency of results when using $get in different parts of the code - even withing the same field for example you will get a different result for dd($get('cars') when using in ->action() and a different one when using in ->visible(). My guess it's because of different life times they are employed, but this is super frustrating. I don't know how to get the current value of my checkbox list. When I do:
dd($get['cars'])
dd($get['cars'])
I will get a list of keys and values. But I don't know which checkbox is toggled on. how to see the real what-I-actually clicked list of items?
46 replies
FFilament
Created by Wirkhof on 3/14/2024 in #❓┊help
I need a one liner to get from this [1, 2, 3] to ["1", "2", "3"]
I am grabbing ids from users:
DB::table('users')
->get()
->pluck('id')
DB::table('users')
->get()
->pluck('id')
and this will give me an array with integers like:
[1, 2, 3, 4, ...]
[1, 2, 3, 4, ...]
However, I need to make it like this:
["1", "2", "3", "4", ...]
["1", "2", "3", "4", ...]
so basically strings in an array, or perhaps json like format, right? The questions is how to do that without a closure or multiple variables or foreach loop etc. Basically I need a one liner to be able to stick it in default() or other form field related parts, etc. I have tried
json_encode(
DB::table('users')
->get()
->pluck('id')
)
json_encode(
DB::table('users')
->get()
->pluck('id')
)
But the result is:
"[1, 2, 3, 4]"
"[1, 2, 3, 4]"
So, it encapsulate the whole array as a string instead of its elements. Any idea how to elegantly solve this problem? Can I perhaps cast somehow the pluck('id') into string during the get process? Or is there some trick how to do this easy?
14 replies
FFilament
Created by Wirkhof on 3/14/2024 in #❓┊help
How to prevent showing Success notification on the Edit page?
I am using a custom button with a custom action on the Edit page. And when pressed, it shows 2 notifications instead of just 1. The first one is the classic Saved successfullly success message that is part of the save buttons. The second one is the custom message of mine I put on the button. Here is the custom-button's code I am using:
Action::make('pending')
->label('Pending')
->action(function () {
$this->data['status'] = 'pending';
$this->save();

$this->refreshFormData([]);

Notification::make()->title("It's pending!")->success()->send();
}),
Action::make('pending')
->label('Pending')
->action(function () {
$this->data['status'] = 'pending';
$this->save();

$this->refreshFormData([]);

Notification::make()->title("It's pending!")->success()->send();
}),
The problem is that not only the "It's pending" notification is shown, but also the "Saved successfully" notification toast as well. How to disable that saved successfully message and show only the my custom notification message?
18 replies
FFilament
Created by Wirkhof on 3/14/2024 in #❓┊help
How to hard page reload after Update button's action is done?
The current state of the Update button on the edit page is that it doesn't hard reload the page. But I need that somehow. How to do that? Basically I want that after the update the whole page is hard reloaded - like when you presse cmd + R or ctrl + R in browser.
23 replies
FFilament
Created by Wirkhof on 3/13/2024 in #❓┊help
How to limit checkbox mouse clicks only on the checkbox and not the label as well?
I have a specific use case when I need to be able to copy some parts of the label for each of the checkboxes in the checkbox list. However, the problem is that a lot of times I toggle the checkbox when I try to copy something from the description or label. How to make the label text itself make to not toggle the checkbox itself?
2 replies
FFilament
Created by Wirkhof on 3/13/2024 in #❓┊help
How to change the breadcrumbs' uppercasing of each word on a listing/edit/create page?
I have tried:
protected static ?string $navigationLabel = 'Cars users like';
protected static ?string $navigationLabel = 'Cars users like';
and
protected static ?string $title = 'Cars user like';
protected static ?string $title = 'Cars user like';
and
protected ?string $heading = 'Cars users like';
protected ?string $heading = 'Cars users like';
and
protected static ?string $pluralModelLabel = 'Cars users like';
protected static ?string $pluralModelLabel = 'Cars users like';
But nothing works and the breadcrumb is uppercasing every word like "Cars Users Like" instead of prefered "Cars users like". By trying things out I have found out that $pluralModelLabel is in fact used to make breadcrumbs. The problem is that uppercasing each word looks much worse in my language that is not English. How do I turn off the uppercasing of each word in breadcrumbs?
6 replies
FFilament
Created by Wirkhof on 3/13/2024 in #❓┊help
How to display a custom message when there are no options to display in Checkbox list?
Is there a way to display a custom message to the user when there are no options do display in Checkbox list? I have found only this: https://filamentphp.com/docs/3.x/forms/fields/checkbox-list#setting-a-custom-no-search-results-message but it's for search and I am not using search. My usecase is that I am looking for DB records and I am displaying them in the Checklist. However, there could be a situation when there are no records at all. So, how to deal with that?
6 replies