F
Filament7mo ago
Noor

Status color options

I have a status table where there are various status options for instance new , old, cold, taken etc . What I want the user have access to choose color of their own choice so what would be the right approch to do that using colorpicker or what else ? I've used colorpicker before but did not worked in this case. Can someone guide me on this please
16 Replies
Dennis Koch
Dennis Koch7mo ago
If you’d explain why a color picker didn’t work maybe we could suggest something else.
Noor
NoorOP7mo ago
On component
protected function getTableColumns(): array
{
return [
ColorColumn::make('color'),
];
}
protected function getTableColumns(): array
{
return [
ColorColumn::make('color'),
];
}
protected function getTableHeaderActions(): array
{
return [
ColorPicker::make('color')->required(),
])
];
}
protected function getTableHeaderActions(): array
{
return [
ColorPicker::make('color')->required(),
])
];
}
protected function getTableActions(): array
{
return [
ColorPicker::make('color')->required(),
]),
];
}
protected function getTableActions(): array
{
return [
ColorPicker::make('color')->required(),
]),
];
}
Database
public function up(): void
{
Schema::create('statuses', function (Blueprint $table) {
$table->id();
$table->string('color');
$table->timestamps();
});
}
public function up(): void
{
Schema::create('statuses', function (Blueprint $table) {
$table->id();
$table->string('color');
$table->timestamps();
});
}
it's all simple but its not working I don't know the exact issue either its not catching the color or getting it in the db idk For some reason its not working
Dennis Koch
Dennis Koch7mo ago
Is the color column fillable?
Noor
NoorOP7mo ago
fillable as in ?
Dennis Koch
Dennis Koch7mo ago
Fillable as in $fillable on your Eloquent Model
Noor
NoorOP7mo ago
o yeah it is fillable
Dennis Koch
Dennis Koch7mo ago
Wait. You just returned a form field for an Action? That should throw an exception and not just "not work" 🤔 Use an Action with a form that updates your model
Noor
NoorOP7mo ago
so is that wrong ?
Dennis Koch
Dennis Koch7mo ago
Yes, it is wrong. Otherwise it would work and I would suggest an alternative. getTableActions expects an array of Actions. Check the Action docs: https://filamentphp.com/docs/3.x/actions/overview#what-is-an-action
Noor
NoorOP7mo ago
ok I'll check that thanks Hello again, the colors are getting stored in database but it is not changing the color of status when I choose different colors for them why ?
Dennis Koch
Dennis Koch7mo ago
What's the color format in the database? Is the column even showing?
Noor
NoorOP7mo ago
hex its showing the column I have the status column in leads and leads option has this setting where I have the permission to choose color for users
awcodes
awcodes7mo ago
You’re storing the values as hex, so in your column you need to return the color as Color::hex($value). Since they aren’t colors registered with filament.
Noor
NoorOP7mo ago
so what type of color format is registered with filament if not hex can I use some other type ? what about this $table->string('color'); ?
Dennis Koch
Dennis Koch7mo ago
That’s not mentioned in the docs. Don’t think that’s needed 🤔
Noor
NoorOP7mo ago
:squint: This is what I have in my lead resource
Tables\Columns\TextColumn::make('status.name')->sortable()
->badge()
->color(fn (string $state): string => match ($state) {
'Cold' => 'gray',
'Taken' => 'warning',
'Won' => 'success',
'Lost' => 'danger',
'New' => 'info',
default => 'primary',
}),
Tables\Columns\TextColumn::make('status.name')->sortable()
->badge()
->color(fn (string $state): string => match ($state) {
'Cold' => 'gray',
'Taken' => 'warning',
'Won' => 'success',
'Lost' => 'danger',
'New' => 'info',
default => 'primary',
}),
And this is what I have in app/Filament/Widgets/Options/Statuses.php
protected function getTableActions(): array
{
return [
EditAction::make()->form([
TextInput::make('name')->required(),
TextInput::make('order')->numeric()->default(0)->minValue(0)->maxValue(32767),
ColorPicker::make('color')->required(),
])
//->using(function ( Status $record , array $data) {
// $record->update($data);
// return $record;
// }),

DeleteAction::make()->disabled(static fn (Status $record) => $record->leads->count() > 0),

];
}
protected function getTableActions(): array
{
return [
EditAction::make()->form([
TextInput::make('name')->required(),
TextInput::make('order')->numeric()->default(0)->minValue(0)->maxValue(32767),
ColorPicker::make('color')->required(),
])
//->using(function ( Status $record , array $data) {
// $record->update($data);
// return $record;
// }),

DeleteAction::make()->disabled(static fn (Status $record) => $record->leads->count() > 0),

];
}
I have the status column in leads and leads option has this setting statuses where I have the permission to choose color for users ??
Want results from more Discord servers?
Add your server