F
Filament3mo ago
HeyWeb

Update value

When I update the registration field it does not update the owner field, it returns a blank value Forms\Components\Select::make('vehiculos_id')->required()->label('Matricula') ->searchable() ->relationship('vehiculos','matricula') ->afterStateUpdated(function (Set $set) { $set('partes.vehiculos_id', null); })
->preload()->live(), Forms\Components\TextInput::make('partes.vehiculos_id')->label('Propietario') ->formatStateUsing(function ($state, Parte $partes) { if (!empty($partes->vehiculos->clientes)) { return $partes->vehiculos->clientes->apellidos . ', ' . $partes->vehiculos->clientes->nombre; } else { return null; } }) ->disabled()->live(),
8 Replies
Dennis Koch
Dennis Koch3mo ago
I think formatStateUsing() only runs on initial load.
HeyWeb
HeyWeb3mo ago
Correct and seo works perfectly, what I don't give is implementing a get to collect the values ​​of the previous field when it is updated
Povilas K
Povilas K3mo ago
@HeyWeb I think you're doing something really in the wrong direction, cause you're having a text input for partes.vehiculos_id but trying to fill it with nombre of clientes, so it isn't actually the ID field? I would probably re-think your approach in general, but too little information to advise on that
HeyWeb
HeyWeb3mo ago
From the license plate I look for which vehicle it belongs to and by the vehicle_id I look in the table to which client it belongs to, it is a purely informative field Parts (license)->vehicle_id->customer_id The problem is that when updating the registration field, the customer field remains blank, because it does not collect the set that is sent to it or it was sent incorrectly.
HeyWeb
HeyWeb3mo ago
No description
Povilas K
Povilas K3mo ago
But you're setting it to null yourself:
->afterStateUpdated(function (Set $set) {
$set('partes.vehiculos_id', null);
})
->afterStateUpdated(function (Set $set) {
$set('partes.vehiculos_id', null);
})
Shouldn't it set the value exactly here, instead of null?
Povilas K
Povilas K3mo ago
Here's a code example of erpsaas open-source project:
Forms\Components\Select::make('currency.code')
->localizeLabel()
->searchable()
->options(CurrencyAccessor::getAvailableCurrencies())
->live()
->afterStateUpdated(static function (callable $set, $state) {
$currency_code = currency($state);
$set('currency.name', $currency_code->getName() ?? '');
})
->required(),
Forms\Components\TextInput::make('currency.name')
->localizeLabel()
->maxLength(100)
->required(),
Forms\Components\Select::make('currency.code')
->localizeLabel()
->searchable()
->options(CurrencyAccessor::getAvailableCurrencies())
->live()
->afterStateUpdated(static function (callable $set, $state) {
$currency_code = currency($state);
$set('currency.name', $currency_code->getName() ?? '');
})
->required(),
Forms\Components\TextInput::make('currency.name')
->localizeLabel()
->maxLength(100)
->required(),
https://github.com/andrewdwallo/erpsaas/blob/ec56e8ece6000fbe3faeddf59a7d81a44e727dd5/app/Filament/Company/Resources/Banking/AccountResource.php#L107C41-L132C58
GitHub
erpsaas/app/Filament/Company/Resources/Banking/AccountResource.php ...
A Laravel and Filament-powered accounting platform, crafting a modern and automated solution for financial management. - andrewdwallo/erpsaas
HeyWeb
HeyWeb3mo ago
Thanks