© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
9 replies
howdu

Set value of another field from within default

Can I set the value of the
key
key
from within the default of the
name
name
. Ideally I don't want to duplicate the logic fetching the default
name
name
.

Forms\Components\TextInput::make('name')
    ->afterStateUpdated(function (\Closure $set, ?string $state):void {
        $set('key', Str::slug($state));
    })
    ->default(function (\Closure $set): string {
        $name = 'Complicated logic';
        $set('key', Str::slug($name));
        return $name;
    })
    ->reactive()
    ->required(),

Forms\Components\TextInput::make('key'),
Forms\Components\TextInput::make('name')
    ->afterStateUpdated(function (\Closure $set, ?string $state):void {
        $set('key', Str::slug($state));
    })
    ->default(function (\Closure $set): string {
        $name = 'Complicated logic';
        $set('key', Str::slug($name));
        return $name;
    })
    ->reactive()
    ->required(),

Forms\Components\TextInput::make('key'),


If you put the
key
key
input first it works. I think the
default
default
is getting called before all the fields are registered is there a way around this?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Set FileUpload value from another field
FilamentFFilament / ❓┊help
2y ago
Value from another field
FilamentFFilament / ❓┊help
3y ago
Set value of key-value field
FilamentFFilament / ❓┊help
3y ago
How to set value to createOptionForm from another field?
FilamentFFilament / ❓┊help
2y ago