F
Filament15mo ago
N1XN

Save prefix values

How can I save the TextInput including the prefix? I know that I can extend the handleRecordCreation method but then I would have the string prefix saved to DB (this is actually wanted and needed) but showing or editing the record would have the prefix and the prefixed string - basically double prefixed.
Select::make('group_id')
->label('Group')
->relationship('group', 'code')
->reactive()
->required(),

TextInput::make('code')
->label('Party code')
->prefix(fn (Closure $get) => $get('group_id') ? Party::find($get('group_id'))->code.'-' : '')
->required(),
Select::make('group_id')
->label('Group')
->relationship('group', 'code')
->reactive()
->required(),

TextInput::make('code')
->label('Party code')
->prefix(fn (Closure $get) => $get('group_id') ? Party::find($get('group_id'))->code.'-' : '')
->required(),
Solution:
Some magic is happening behind the scenes I did not understood, so my workaround is: remove ->reactive() and set the value directly after update using ->afterStateUpdated(fn ($state, callable $set) => $set('code', Party::find($state)->code.'-'))...
Jump to solution
1 Reply
Solution
N1XN
N1XN15mo ago
Some magic is happening behind the scenes I did not understood, so my workaround is: remove ->reactive() and set the value directly after update using ->afterStateUpdated(fn ($state, callable $set) => $set('code', Party::find($state)->code.'-'))

Did you find this page helpful?