mask money comma separate is not working
Forms\Components\Select::make('product_id')
->label('Product')
->options(Product::query()->pluck('name', 'id'))
->required()
->reactive()
->afterStateUpdated(
fn(
$state,
Forms\Set $set
) => $set(
'unit_price',
Product::find($state)?->price *
Product::find($state)?->currency->rate *
(1 + Product::find($state)?->margin / 100) ?? 0,
)
)
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->columnSpan([
'md' => 5,
])
->searchable(),
Forms\Components\TextInput::make('qty')
->label('Quantity')
->numeric()
->default(1)
->columnSpan([
'md' => 2,
])
->required(),
Forms\Components\TextInput::make('unit_price')
->label('Unit Price')
->disabled()
->dehydrated()
->live()
->mask(RawJs::make(<<<'JS'
$money($input, '.', ',')
JS))
->numeric()
->required()
->columnSpan([
'md' => 3,
])
Forms\Components\Select::make('product_id')
->label('Product')
->options(Product::query()->pluck('name', 'id'))
->required()
->reactive()
->afterStateUpdated(
fn(
$state,
Forms\Set $set
) => $set(
'unit_price',
Product::find($state)?->price *
Product::find($state)?->currency->rate *
(1 + Product::find($state)?->margin / 100) ?? 0,
)
)
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->columnSpan([
'md' => 5,
])
->searchable(),
Forms\Components\TextInput::make('qty')
->label('Quantity')
->numeric()
->default(1)
->columnSpan([
'md' => 2,
])
->required(),
Forms\Components\TextInput::make('unit_price')
->label('Unit Price')
->disabled()
->dehydrated()
->live()
->mask(RawJs::make(<<<'JS'
$money($input, '.', ',')
JS))
->numeric()
->required()
->columnSpan([
'md' => 3,
])
Solution:Jump to solution
```php
Forms\Components\Select::make('product_id')
->label('Product')
->options(Product::query()->pluck('name', 'id'))
->required()...
12 Replies
remove
numeric()
still not working
are you using the panel builder?
Yes
I just copy from demo code
could you share an image with the field?
TextInput::make('unit_price')
->label('Unit Price')
->disabled()
->formatStateUsing(fn () => 1440000)
->mask(RawJs::make(<<<'JS'
$money($input, '.', ',')
JS))
TextInput::make('unit_price')
->label('Unit Price')
->disabled()
->formatStateUsing(fn () => 1440000)
->mask(RawJs::make(<<<'JS'
$money($input, '.', ',')
JS))
Thank you let me check
It's still
not working
maybe that code wrong
Forms\Components\Select::make('product_id')
->label('Product')
->options(Product::query()->pluck('name', 'id'))
->required()
->reactive()
->afterStateUpdated(
fn(
$state,
Forms\Set $set
) => $set(
'unit_price',
Product::find($state)?->price *
Product::find($state)?->currency->rate *
(1 + Product::find($state)?->margin / 100) ?? 0,
)
Forms\Components\Select::make('product_id')
->label('Product')
->options(Product::query()->pluck('name', 'id'))
->required()
->reactive()
->afterStateUpdated(
fn(
$state,
Forms\Set $set
) => $set(
'unit_price',
Product::find($state)?->price *
Product::find($state)?->currency->rate *
(1 + Product::find($state)?->margin / 100) ?? 0,
)
Forms\Components\TextInput::make('unit_price')
->label('Unit Price')
->disabled()
->formatStateUsing(fn (?int $state): ?int => $state)
->mask(RawJs::make(<<<'JS'
$money($input, ',', '.')
JS))
->required()
//
Forms\Components\TextInput::make('unit_price')
->label('Unit Price')
->disabled()
->formatStateUsing(fn (?int $state): ?int => $state)
->mask(RawJs::make(<<<'JS'
$money($input, ',', '.')
JS))
->required()
//
maybe you could create a minimal repo on github to reproduce this issue
Thank you so much
Solution
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',
Number::format(
Product::find($state)?->price *
Product::find($state)?->currency->rate *
(1 + Product::find($state)?->margin / 100) ?? 0
),
)
)
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',
Number::format(
Product::find($state)?->price *
Product::find($state)?->currency->rate *
(1 + Product::find($state)?->margin / 100) ?? 0
),
)
)