diff --git a/src/Field/AbstractField.php b/src/Field/AbstractField.php index 2df6b0e..67791be 100644 --- a/src/Field/AbstractField.php +++ b/src/Field/AbstractField.php @@ -14,6 +14,7 @@ ManageLabelTrait, ManageRenderTrait, ManageWrapperTrait}; +use Windwalker\Form\Attributes\Fieldset; use Windwalker\Form\Form; use Windwalker\Form\FormNormalizer; use Windwalker\Form\FormRegistry; @@ -342,12 +343,16 @@ public function getFieldset(): ?string /** * Method to set property fieldset * - * @param ?string $fieldset + * @param Fieldset|string|null $fieldset * * @return static Return self to support chaining. */ - public function setFieldset(?string $fieldset): static + public function setFieldset(Fieldset|string|null $fieldset): static { + if ($fieldset instanceof Fieldset) { + $fieldset = $fieldset->getName(); + } + $this->fieldset = $fieldset; return $this; diff --git a/src/Form.php b/src/Form.php index 110686a..7f1ce94 100644 --- a/src/Form.php +++ b/src/Form.php @@ -152,14 +152,12 @@ public function addField( Fieldset|string|null $fieldset = null, string $namespace = '' ): AbstractField { - if ($fieldset) { - $fieldset = $this->fieldset($fieldset); - } else { + if ($fieldset === null) { $fieldset = $this->fieldset; } - if ($fieldset) { - $field->setFieldset($fieldset->getName()); + if ($fieldset !== null) { + $field->setFieldset($fieldset); } if (!$namespace) {