© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago•
4 replies
Shaung Bhone

How can I format price without focus?

Forms\Components\Select::make('product_id')
    ->label('Product')
    ->options(Product::query()->pluck('name', 'id'))
    ->required()
    ->live(onBlur: true)
    ->afterStateUpdated(
        fn(
        $state,
        Forms\Set $set
    ) => $set(
            'unit_price',
            Product::find($state)?->price ?? 0,
        )
    ),
...
Forms\Components\TextInput::make('unit_price')
    ->label('Unit Price')
    ->required()
    ->inputMode('decimal')
    ->numeric()
    ->mask(RawJs::make('$money($input)'))
    ->stripCharacters(',')
    ->columnSpan([
        'md' => 3,
    ]),
Forms\Components\Select::make('product_id')
    ->label('Product')
    ->options(Product::query()->pluck('name', 'id'))
    ->required()
    ->live(onBlur: true)
    ->afterStateUpdated(
        fn(
        $state,
        Forms\Set $set
    ) => $set(
            'unit_price',
            Product::find($state)?->price ?? 0,
        )
    ),
...
Forms\Components\TextInput::make('unit_price')
    ->label('Unit Price')
    ->required()
    ->inputMode('decimal')
    ->numeric()
    ->mask(RawJs::make('$money($input)'))
    ->stripCharacters(',')
    ->columnSpan([
        'md' => 3,
    ]),
Solution
https://filamentphp.com/docs/3.x/forms/advanced#field-hydration
Advanced forms - Form Builder - Filament
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to format price in form?
FilamentFFilament / ❓┊help
12mo ago
How can I stop afterStateUpdated from stealing focus?
FilamentFFilament / ❓┊help
13mo ago
How can I format text column as downloadable link?
FilamentFFilament / ❓┊help
3y ago
How can change the focus-ring for input
FilamentFFilament / ❓┊help
2y ago