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,
    ]),
Was this page helpful?