From 1689d790ecfa4b57076f8e77d9e5cfb994f97b52 Mon Sep 17 00:00:00 2001 From: Ron Chaplin Date: Thu, 18 Jul 2024 09:11:20 -0500 Subject: [PATCH] LWB-264 Fixing the FormRelatedAttributes Trait logic --- src/Components/AttributeTraits/FormRelatedAttributes.php | 4 ++-- src/Components/Forms/Button.php | 2 +- src/Components/Forms/Inputs/Button.php | 2 +- src/Components/Forms/Inputs/Image.php | 1 + src/Components/Forms/Inputs/Submit.php | 2 +- tests/Feature/Traits/FormsRelatedAttributesTest.php | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Components/AttributeTraits/FormRelatedAttributes.php b/src/Components/AttributeTraits/FormRelatedAttributes.php index 26928fe7..9d9c06d8 100644 --- a/src/Components/AttributeTraits/FormRelatedAttributes.php +++ b/src/Components/AttributeTraits/FormRelatedAttributes.php @@ -66,7 +66,7 @@ trait FormRelatedAttributes * * @throws \T73biz\LwBits\Exceptions\InvalidAttributeException */ - public function setFormRelatedAttributes(AttributeCollection &$specificAttributes): void + public function setFormRelatedAttributes(AttributeCollection &$specificAttributes, string $type): void { if (! empty($this->formaction)) { if (empty($this->form)) { @@ -78,7 +78,7 @@ public function setFormRelatedAttributes(AttributeCollection &$specificAttribute if (empty($this->form)) { throw new InvalidAttributeException('The formenctype attribute requires form attribute to be set.'); } - if (! empty($this->type) && ! in_array($this->type, ['submit', 'image'])) { + if (! in_array($type, ['submit', 'image'])) { throw new InvalidAttributeException( 'The formenctype attribute requires type attribute to be set to submit or image.' ); diff --git a/src/Components/Forms/Button.php b/src/Components/Forms/Button.php index 75edda06..081bd81f 100644 --- a/src/Components/Forms/Button.php +++ b/src/Components/Forms/Button.php @@ -79,7 +79,7 @@ public function mount(): void { $this->setGlobalAttributes(); $this->specificAttributes = new AttributeCollection(); - $this->setFormRelatedAttributes($this->specificAttributes); + $this->setFormRelatedAttributes($this->specificAttributes, $this->type); $this->setPopoverAttributes($this->specificAttributes); if ($this->disabled) { $this->specificAttributes->add(['disabled']); diff --git a/src/Components/Forms/Inputs/Button.php b/src/Components/Forms/Inputs/Button.php index 8fa62c64..e8098049 100644 --- a/src/Components/Forms/Inputs/Button.php +++ b/src/Components/Forms/Inputs/Button.php @@ -38,7 +38,7 @@ public function mount(): void { $this->setGlobalAttributes(); $this->specificAttributes = new AttributeCollection(); - $this->setFormRelatedAttributes($this->specificAttributes); + $this->setFormRelatedAttributes($this->specificAttributes, 'button'); $this->setGenericInputAttributes($this->specificAttributes); $this->setPopoverAttributes($this->specificAttributes); } diff --git a/src/Components/Forms/Inputs/Image.php b/src/Components/Forms/Inputs/Image.php index 0dec5980..89beed25 100644 --- a/src/Components/Forms/Inputs/Image.php +++ b/src/Components/Forms/Inputs/Image.php @@ -45,6 +45,7 @@ public function mount(): void $this->setAltAttribute($this->specificAttributes); $this->setDimensionalAttributes($this->specificAttributes); $this->setGenericInputAttributes($this->specificAttributes); + $this->setFormRelatedAttributes($this->specificAttributes, 'image'); $this->setSrcAttribute($this->specificAttributes, true); } diff --git a/src/Components/Forms/Inputs/Submit.php b/src/Components/Forms/Inputs/Submit.php index 250c3ccf..0bc3d22b 100644 --- a/src/Components/Forms/Inputs/Submit.php +++ b/src/Components/Forms/Inputs/Submit.php @@ -36,7 +36,7 @@ public function mount(): void { $this->setGlobalAttributes(); $this->specificAttributes = new AttributeCollection(); - $this->setFormRelatedAttributes($this->specificAttributes); + $this->setFormRelatedAttributes($this->specificAttributes, 'submit'); $this->setGenericInputAttributes($this->specificAttributes); } diff --git a/tests/Feature/Traits/FormsRelatedAttributesTest.php b/tests/Feature/Traits/FormsRelatedAttributesTest.php index 3e4903de..9ab17949 100644 --- a/tests/Feature/Traits/FormsRelatedAttributesTest.php +++ b/tests/Feature/Traits/FormsRelatedAttributesTest.php @@ -1,7 +1,7 @@