how to identify which button triggered action in single form with multiple buttons

I have a resource that in edit page
Forms\Components\TextInput::make('reference')
->unique(ignoreRecord: true, modifyRuleUsing: function (Unique $rule, $get) {
return $rule->where('status', 'approved');
})
Forms\Components\TextInput::make('reference')
->unique(ignoreRecord: true, modifyRuleUsing: function (Unique $rule, $get) {
return $rule->where('status', 'approved');
})
I added an additional action
protected function getFormActions(): array
{
return [
$this->getSaveFormAction()
->label('Approve')
->color('success'),
Action::make('reject')
->action('reject')
->color('warning')
->label('Reject'),
$this->getCancelFormAction(),
];
}

public function reject()
{
$data = $this->form->getState();
// ...
}
protected function getFormActions(): array
{
return [
$this->getSaveFormAction()
->label('Approve')
->color('success'),
Action::make('reject')
->action('reject')
->color('warning')
->label('Reject'),
$this->getCancelFormAction(),
];
}

public function reject()
{
$data = $this->form->getState();
// ...
}
now the question is, if the record that I'm going to reject, I don't need the to validate the uniqueness of the reference field, how can I achieve this
Solution:
solution ```php // add this to edit page protected bool $rejectSubmission = false; ...
Jump to solution
1 Reply
Solution
wyChoong
wyChoong14mo ago
solution
// add this to edit page
protected bool $rejectSubmission = false;

public function reject()
{
$this->rejectSubmission = true; // set to true

$data = $this->form->getState();
// ...
}
// add this to edit page
protected bool $rejectSubmission = false;

public function reject()
{
$this->rejectSubmission = true; // set to true

$data = $this->form->getState();
// ...
}
in form schema
Forms\Components\TextInput::make('reference')
->unique(
fn ($livewire) => $livewire->isRejectSubmission() ? false : null, // return false to disable, return null so filament will figure the table name itself or you can provide the table name here
// ...
)
Forms\Components\TextInput::make('reference')
->unique(
fn ($livewire) => $livewire->isRejectSubmission() ? false : null, // return false to disable, return null so filament will figure the table name itself or you can provide the table name here
// ...
)
Want results from more Discord servers?
Add your server