Skip to content

Commit

Permalink
Add form reference to field during render
Browse files Browse the repository at this point in the history
  • Loading branch information
martyf committed Oct 18, 2023
1 parent bbf6c19 commit 58e263e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Field implements Arrayable
protected $parent;
protected $parentField;
protected $validationContext;
protected $form;

public function __construct($handle, array $config)
{
Expand Down Expand Up @@ -409,4 +410,16 @@ public function isRelationship(): bool
{
return $this->fieldtype()->isRelationship();
}

public function setForm($form)
{
$this->form = $form;

return $this;
}

public function form()
{
return $this->form;
}
}
4 changes: 4 additions & 0 deletions src/Tags/Concerns/RendersForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ protected function getRenderableField($field, $errorBag = 'default', $manipulate
{
$errors = session('errors') ? session('errors')->getBag($errorBag) : new MessageBag;

if (method_exists($this, 'form')) {
$field->setForm($this->form());
}

$missing = str_random();
$old = old($field->handle(), $missing);
$default = $field->value() ?? $field->defaultValue();
Expand Down

0 comments on commit 58e263e

Please sign in to comment.