Set value of another field from within default

Can I set the value of the key from within the default of the
name
. Ideally I don't want to duplicate the logic fetching the default
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'),


If you put the key input first it works. I think the default is getting called before all the fields are registered is there a way around this?
Was this page helpful?