|
16 | 16 | use Illuminate\Session\Store;
|
17 | 17 | use Illuminate\Support\Arr;
|
18 | 18 | use Illuminate\Support\HtmlString;
|
| 19 | +use Illuminate\Support\MessageBag; |
19 | 20 | use Illuminate\Support\Str;
|
20 | 21 | use Illuminate\Support\ViewErrorBag;
|
21 | 22 | use stdClass;
|
@@ -102,13 +103,13 @@ class Form extends \Galahad\Aire\DTD\Form implements NonInput
|
102 | 103 | * @var string
|
103 | 104 | */
|
104 | 105 | protected $form_request;
|
105 |
| - |
| 106 | + |
106 | 107 | /**
|
107 | 108 | * Custom error bag
|
108 | 109 | *
|
109 | 110 | * @var string
|
110 | 111 | */
|
111 |
| - protected $error_bag = null; |
| 112 | + protected $error_bag = 'default'; |
112 | 113 |
|
113 | 114 | /**
|
114 | 115 | * Set to true to load development versions of JS
|
@@ -330,28 +331,16 @@ public function getBoundValue($name, $default = null)
|
330 | 331 | /**
|
331 | 332 | * Get any validation errors associated with an Element
|
332 | 333 | *
|
333 |
| - * @param string $name |
334 |
| - * @return array |
| 334 | + * @param ?string $name |
| 335 | + * @return MessageBag|array |
335 | 336 | */
|
336 |
| - public function getErrors(string $name): array |
| 337 | + public function getErrors(string $name = null) |
337 | 338 | {
|
338 |
| - if (!$errors = $this->session_store->get('errors')) { |
339 |
| - return []; |
340 |
| - } |
| 339 | + $errors = $this->session_store |
| 340 | + ->get('errors', new ViewErrorBag()) |
| 341 | + ->getBag($this->error_bag); |
341 | 342 |
|
342 |
| - if (!$errors instanceof ViewErrorBag) { |
343 |
| - return []; |
344 |
| - } |
345 |
| - |
346 |
| - if ($this->error_bag) { |
347 |
| - $errors = $errors->getBag($this->error_bag); |
348 |
| - } |
349 |
| - |
350 |
| - if (!$errors->has($name)) { |
351 |
| - return []; |
352 |
| - } |
353 |
| - |
354 |
| - return $errors->get($name); |
| 343 | + return $name ? $errors->get($name) : $errors; |
355 | 344 | }
|
356 | 345 |
|
357 | 346 | /**
|
@@ -417,7 +406,13 @@ public function closeButton(): Button
|
417 | 406 |
|
418 | 407 | return $button;
|
419 | 408 | }
|
420 |
| - |
| 409 | + |
| 410 | + /** |
| 411 | + * Set the name of the error bag to use for error messages |
| 412 | + * |
| 413 | + * @param string $name |
| 414 | + * @return $this |
| 415 | + */ |
421 | 416 | public function errorBag($name): self
|
422 | 417 | {
|
423 | 418 | $this->error_bag = $name;
|
|
0 commit comments