Insert value from one field to another

Hi, I would like to auto generate the email for my user form from the first and lastname. I tried this, but it didn't work:
CreateAction::make()->form([
Grid::make(2)->schema([
TextInput::make('firstname')
->reactive()
->required(),
TextInput::make('lastname')
->reactive(),
->required(),
]),
TextInput::make('email')
->suffix('@company.com')
->default(fn($get) => $get('firstname') . '.' . $get('lastname'))
->unique()
->required()
]);
CreateAction::make()->form([
Grid::make(2)->schema([
TextInput::make('firstname')
->reactive()
->required(),
TextInput::make('lastname')
->reactive(),
->required(),
]),
TextInput::make('email')
->suffix('@company.com')
->default(fn($get) => $get('firstname') . '.' . $get('lastname'))
->unique()
->required()
]);
How can I make this work? Thank you!
3 Replies
wyChoong
wyChoongβ€’17mo ago
Filament
Advanced - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
Florian Langer
Florian LangerOPβ€’17mo ago
but how should this be done if there are two fields that should manipulate the email field (like in my example)? solved it like this now
TextInput::make('firstname')
->reactive()
->afterStateUpdated(function (Closure $set, $state, $get) {
$set('email', strtolower($state) . '.' . strtolower($get('lastname')));
})
->required(),
TextInput::make('lastname')
->reactive()
->afterStateUpdated(function (Closure $set, $state, $get) {
$set('email', strtolower($get('firstname')) . '.' . strtolower($state));
})
->required(),
TextInput::make('firstname')
->reactive()
->afterStateUpdated(function (Closure $set, $state, $get) {
$set('email', strtolower($state) . '.' . strtolower($get('lastname')));
})
->required(),
TextInput::make('lastname')
->reactive()
->afterStateUpdated(function (Closure $set, $state, $get) {
$set('email', strtolower($get('firstname')) . '.' . strtolower($state));
})
->required(),
But if theres a better way, please tell me πŸ™‚
Patrick Boivin
Patrick Boivinβ€’17mo ago
That's also how I do it, if the field needs to be editable. Otherwise a Placeholder is better if it's just for presentation.
Want results from more Discord servers?
Add your server