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