Shaheen
Shaheen
FFilament
Created by Shaheen on 4/11/2025 in #❓┊help
toggle in input hint
It would be wonderful to be able to achieve something like the following
TextInput::make('brand_name')
->hint(Toggle::make('same_as_company'))
TextInput::make('brand_name')
->hint(Toggle::make('same_as_company'))
I think use cases for this would be endless, one for example is to mirror another input maybe something like this
TextInput::make('company_name')
->debounce()
->afterStateUpdated(fn ($get, $set, $state) =>
$get('same_as_company') ? $set('brand_name', $state) : '')
),

TextInput::make('brand_name')
->hint(Toggle::make('same_as_company')->live())
->disabled(fn ($get) => $get('same_as_company'))
TextInput::make('company_name')
->debounce()
->afterStateUpdated(fn ($get, $set, $state) =>
$get('same_as_company') ? $set('brand_name', $state) : '')
),

TextInput::make('brand_name')
->hint(Toggle::make('same_as_company')->live())
->disabled(fn ($get) => $get('same_as_company'))
I tried to achieve something similar and after hours of trying I did it using hintAction with a custom action and a custom view which renders a toggle
<?php

namespace Modules\Dashboard\Filament\Forms;

use Closure;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Field;

class ToggleHintAction extends Action
{
protected string $view = 'dashboard::components.filament.forms.toggle-hint';
protected ?string $statePath;
protected mixed $defaultState = false;

public function getStatePath()
{
return $this->evaluate(function ($set, Field $component, $get) {
$set($this->getName(), $get($this->getName()) ?? $this->getDefaultState());

return "{$component->getContainer()->getStatePath()}.{$this->getName()}";
});
}

public function default($state): self
{
$this->defaultState = $state;

return $this;
}

public function getDefaultState(): mixed
{
return $this->evaluate($this->defaultState);
}
}
<?php

namespace Modules\Dashboard\Filament\Forms;

use Closure;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Field;

class ToggleHintAction extends Action
{
protected string $view = 'dashboard::components.filament.forms.toggle-hint';
protected ?string $statePath;
protected mixed $defaultState = false;

public function getStatePath()
{
return $this->evaluate(function ($set, Field $component, $get) {
$set($this->getName(), $get($this->getName()) ?? $this->getDefaultState());

return "{$component->getContainer()->getStatePath()}.{$this->getName()}";
});
}

public function default($state): self
{
$this->defaultState = $state;

return $this;
}

public function getDefaultState(): mixed
{
return $this->evaluate($this->defaultState);
}
}
and the most interesting part in the toggle view is for chars limits
x-data={ state: $wire.$entangle('{{ $getStatePath() }}')
x-data={ state: $wire.$entangle('{{ $getStatePath() }}')
which works but I feel it's hacky and not the best way to do it, I'm willing to put the effort to achieve it this is the best I could come up with, any help is appreciated.
2 replies
FFilament
Created by Shaheen on 3/3/2025 in #❓┊help
Placholder component doesn't render state by default
every time I use the Placeholder component I have to manually set the content to the state using Placeholder::make('name')->content(fn($state) => $state) Am I doing something wrong or this is supposed to be default behaviour? if it's default behaviour why is it doesn't have content set to state by default?
3 replies