Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Fix errorbag
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Apr 17, 2016
1 parent 5894619 commit 50d1694
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
use Illuminate\Support\HtmlString;
use Illuminate\Support\MessageBag;
use Illuminate\Support\Collection;
use Illuminate\Routing\UrlGenerator;
use Illuminate\View\Factory;

class FormBuilder extends Form
{
Expand All @@ -14,6 +16,13 @@ class FormBuilder extends Form
protected $isHorizontalForm = false;
protected $framework = 'none';

public function __construct(HtmlBuilder $html, UrlGenerator $url, Factory $view, $csrfToken)
{
parent::__construct($html, $url, $view, $csrfToken);

$this->errors = app('session')->get('errors', new MessageBag());
}

/**
* @param string $returnUrl
*
Expand Down Expand Up @@ -89,8 +98,6 @@ public function select($name, $list = [], $selected = null, $options = [])
*/
public function open(array $options = [])
{
$this->errors = app('session')->get('errors', new MessageBag());

if (array_key_exists('class', $options) && (strpos($options['class'], 'form-horizontal') !== false)) {
$this->isHorizontalForm = true;
}
Expand Down Expand Up @@ -120,6 +127,10 @@ public function model($model, array $options = [])
{
$this->errors = app('session')->get('errors', new MessageBag());

if (! $this->errors) {
$this->errors = new Collection();
}

if (array_key_exists('class', $options) && (strpos($options['class'], 'form-horizontal') !== false)) {
$this->isHorizontalForm = true;
}
Expand Down Expand Up @@ -461,7 +472,11 @@ private function getFormGroupClasses($name)
}

private function getErrorHtml($name) {
if (! $this->hasErrors() xor ! $this->errors->has($name)) {
if (! $this->hasErrors()) {
return '';
}

if (! $this->errors->has($name)) {
return '';
}

Expand Down

0 comments on commit 50d1694

Please sign in to comment.