Add error message to a custom action form

I have a custom action with a form. Is it possible to add an error message to the form?
class FooAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this->form([
Forms\Components\TextInput::make('barcode')
->required(),
])
->action(function (array $data) {
try {
// do something
} catch (InvalidBarcodeException) {
// Typically in a Livewire component I would do something like this
$this->addError('barcode', __('Barcode is invalid.'));
return;
}

// continue executing
});
}
}
class FooAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this->form([
Forms\Components\TextInput::make('barcode')
->required(),
])
->action(function (array $data) {
try {
// do something
} catch (InvalidBarcodeException) {
// Typically in a Livewire component I would do something like this
$this->addError('barcode', __('Barcode is invalid.'));
return;
}

// continue executing
});
}
}
One post here mentioned something like:
throw \Illuminate\Validation\ValidationException::withMessages(['mountedTableActionData.barcode' => 'The barcode is invalid.']);
throw \Illuminate\Validation\ValidationException::withMessages(['mountedTableActionData.barcode' => 'The barcode is invalid.']);
But that didn't work for me.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server