Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Jul 13, 2024
1 parent 4b3ca71 commit f619b83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Support/Html/Elements/Icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Icon extends BaseElement
{
protected $tag = 'span';

public function svg(?string $name = null, ?string $class = null): static
public function svg(?string $name = null, ?string $class = null, ?array $attributes = []): static
{
return $this->html(svg($name, $class)->toHtml());
return $this->html(svg($name, $class, $attributes)->toHtml());
}
}
15 changes: 11 additions & 4 deletions src/Support/Html/Mixins/HtmlExtendedMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Foxws\WireUse\Support\Html\Elements\Icon;
use Foxws\WireUse\Support\Html\Elements\Validate;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\ValidationException;
use Livewire\Form as Livewire;
use Spatie\Html\Elements\Form;

Expand All @@ -16,10 +17,16 @@ class HtmlExtendedMixin

public function wireForm(): mixed
{
return function (Livewire $form, ?string $action = null) {
return function (Livewire $form, ?string $action = null): Form {
$this->form = $form;

$this->errorBag = $form->getErrorBag();
$this->errorBag = null;

try {
$this->form->validate();
} catch (ValidationException $e) {
$this->errorBag = $e->validator->errors();
}

return Form::create()
->attributeIf($action, 'wire:submit', $action);
Expand All @@ -28,7 +35,7 @@ public function wireForm(): mixed

public function closeWireForm(): mixed
{
return function () {
return function (): Form {
$this->form = null;

$this->errorBag = null;
Expand All @@ -46,7 +53,7 @@ public function icon(): mixed

public function validate(): mixed
{
return function (string $field, ?string $message = null) {
return function (string $field, ?string $message = null): Validate {
$hasMessage = $this->errorBag?->has($field);

$message ??= $this->errorBag?->first($field);
Expand Down

0 comments on commit f619b83

Please sign in to comment.