Skip to content

Commit 99fb45e

Browse files
authored
Merge pull request #20 from androzd/master
fix bug with multiple forms on page
2 parents 1dcd252 + 2671655 commit 99fb45e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Form/Element.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ abstract class Element
3131

3232
public function __construct($name, $validators = '', Form $form = null)
3333
{
34+
$isFormSubmitted = is_null($form) || $form->isSubmitted();
35+
3436
$this->name = $name;
3537
$this->elementName = self::prepareElementName($name);
3638
$this->validators = $validators;
@@ -40,16 +42,20 @@ public function __construct($name, $validators = '', Form $form = null)
4042
$oldValue = request()->old($this->name, false);
4143
}
4244
$this->hasOldValue = $oldValue !== false;
43-
$this->value = $oldValue;
4445
$this->error = null;
45-
$isFormSubmitted = is_null($form) || $form->isSubmitted();
4646
$errors = session()->get('errors');
47-
if ($isFormSubmitted && $errors)
47+
48+
if ($isFormSubmitted)
4849
{
49-
$this->error = array_get(array_undot($errors->toArray()), $this->name, '');
50-
if (is_array($this->error))
50+
$this->value = $oldValue;
51+
52+
if ($errors)
5153
{
52-
$this->error = array_first($this->error);
54+
$this->error = array_get(array_undot($errors->toArray()), $this->name, '');
55+
if (is_array($this->error))
56+
{
57+
$this->error = array_first($this->error);
58+
}
5359
}
5460
}
5561
}

0 commit comments

Comments
 (0)