F
Filament4mo ago
monzer

TextInputColumn custom validation error

Tables\Columns\TextInputColumn::make('baseShopItem.discount_price') ->label(__('validation.attributes.discount_price')) ->toggleable() ->rules([ fn (Forms\Get $get): \Closure => function (string $attribute, $value, \Closure $fail) use ($get) { if ($get('baseShopItem.price') > $value) { $fail("The {$attribute} is invalid."); } }, ]) ->extraInputAttributes(['class' => 'min-w-[68px]']), i am getting. App\Filament\Resources{closure}(): Argument #1 ($get) must be of type Filament\Forms\Get, string given
13 Replies
Dennis Koch
Dennis Koch4mo ago
You cannot use $get in a table. There is no form. Isn't the value injected through $state or $value maybe?
monzer
monzerOP4mo ago
The value is injected thats not the issue. I need to get the value of another text input column.
lolmaheen
lolmaheen2w ago
is there a solution for this how can i pass $record in the custom rules
toeknee
toeknee2w ago
You can pass the record class in can't you?
Dennis Koch
Dennis Koch2w ago
Did you try ->rules(fn ($state) =>?
toeknee
toeknee2w ago
But he want's record to get another form value beyond the discount_price?
Dennis Koch
Dennis Koch2w ago
IMO a DataAware rule would be the right solution here.
Dennis Koch
Dennis Koch2w ago
Validation - Laravel 11.x - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
toeknee
toeknee2w ago
Not used this yet... need to look into them myself
Vp
Vp2w ago
Try like this:
Tables\Columns\TextInputColumn::make('baseShopItem.discount_price')
->beforeStateUpdated(function ($record, $state) {
if ($record->price > $state) {
throw ValidationException::withMessages([
'test' => 'Error',
]);
}
}
),
Tables\Columns\TextInputColumn::make('baseShopItem.discount_price')
->beforeStateUpdated(function ($record, $state) {
if ($record->price > $state) {
throw ValidationException::withMessages([
'test' => 'Error',
]);
}
}
),
You can also prompt Notification
Dennis Koch
Dennis Koch2w ago
You slipped some JS syntax in there: $record.price 😅
Vp
Vp2w ago
🤣 updated
lolmaheen
lolmaheen2w ago
thankyou figured this out!

Did you find this page helpful?