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:
```php Forms\Components\Select::make('product_id') ->label('Product') ->options(Product::query()->pluck('name', 'id')) ->required()...
Jump to solution
12 Replies
LeandroFerreira
LeandroFerreira2mo ago
remove numeric()
Shaung Bhone
Shaung Bhone2mo ago
still not working
LeandroFerreira
LeandroFerreira2mo ago
are you using the panel builder?
Shaung Bhone
Shaung Bhone2mo ago
Yes I just copy from demo code
LeandroFerreira
LeandroFerreira2mo ago
could you share an image with the field?
Shaung Bhone
Shaung Bhone2mo ago
No description
LeandroFerreira
LeandroFerreira2mo ago
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))
Could you try my code?
No description
Shaung Bhone
Shaung Bhone2mo ago
Thank you let me check It's still 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,
)

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,
)

maybe that code wrong
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()
//
Shaung Bhone
Shaung Bhone2mo ago
No description
LeandroFerreira
LeandroFerreira2mo ago
maybe you could create a minimal repo on github to reproduce this issue
Shaung Bhone
Shaung Bhone2mo ago
Thank you so much
Solution
Shaung Bhone
Shaung Bhone2mo ago
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
),
)
)
Want results from more Discord servers?
Add your server