F
Filament2mo ago
RawaN

Modal Action not work

->extraModalFooterActions([
Action::make('250dinar')
->label('250 Dinar')
->extraAttributes(['class' => 'w-1/2 !h-full'])
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 250);
}),
Action::make('500dinar')
->label('500 Dinar')
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 500);
}),
Action::make('1hazar')
->label('1 Hazar')
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 1000);
}),
Action::make('5hazar')
->label('5 Hazar')
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 5000);
}),
Action::make('10hazar')
->label('10 Hazar')
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 10000);
}),
])
->extraModalFooterActions([
Action::make('250dinar')
->label('250 Dinar')
->extraAttributes(['class' => 'w-1/2 !h-full'])
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 250);
}),
Action::make('500dinar')
->label('500 Dinar')
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 500);
}),
Action::make('1hazar')
->label('1 Hazar')
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 1000);
}),
Action::make('5hazar')
->label('5 Hazar')
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 5000);
}),
Action::make('10hazar')
->label('10 Hazar')
->action(function (Get $get, Set $set) {
$this->updatePaidAndPayback($get, $set, 10000);
}),
])
My main issue is this error Typed property Filament\Forms\Components\Actions\Action::$component must not be accessed before initialization i don't know what to do
2 Replies
ChesterS
ChesterS2mo ago
We need more info. Like what does the updatePaidAndPayback() function do?
RawaN
RawaN2mo ago
This is the function
public function updatePaidAndPayback(Get $get, Set $set, int $value): void
{
$totalPrice = (int) $get('total_price');
$paidPrice = (int) $get('paid_price') + $value;

if ($paidPrice > $totalPrice) {
Notification::make()
->title('Error')
->body('Paid price cannot be greater than total price.')
->danger()
->send();
return;
}

$paybackPrice = max(0, $totalPrice - $paidPrice);

$set('paid_price', $paidPrice);
$set('payback_price', number_format($paybackPrice));
}
public function updatePaidAndPayback(Get $get, Set $set, int $value): void
{
$totalPrice = (int) $get('total_price');
$paidPrice = (int) $get('paid_price') + $value;

if ($paidPrice > $totalPrice) {
Notification::make()
->title('Error')
->body('Paid price cannot be greater than total price.')
->danger()
->send();
return;
}

$paybackPrice = max(0, $totalPrice - $paidPrice);

$set('paid_price', $paidPrice);
$set('payback_price', number_format($paybackPrice));
}
But i think the main reason is the actions not work up
Want results from more Discord servers?
Add your server