Skip to content

Commit

Permalink
FieldsetElement: Correctly handle elements with multiple values
Browse files Browse the repository at this point in the history
fixes #136
  • Loading branch information
nilmerg committed Jun 10, 2024
1 parent 06a73e8 commit d212a43
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/FormElement/FieldsetElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ipl\Html\FormElement;

use InvalidArgumentException;
use ipl\Html\Common\MultipleAttribute;
use ipl\Html\Contract\FormElement;
use ipl\Html\Contract\FormElementDecorator;
use ipl\Html\Contract\Wrappable;
Expand Down Expand Up @@ -107,15 +108,23 @@ public function setWrapper(Wrappable $wrapper)
protected function onElementRegistered(FormElement $element)
{
$element->getAttributes()->registerAttributeCallback('name', function () use ($element) {
$multiple = false;
if (in_array(MultipleAttribute::class, class_uses($element), true)) {
$multiple = $element->isMultiple();

Check failure on line 113 in src/FormElement/FieldsetElement.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Call to an undefined method ipl\Html\Contract\FormElement::isMultiple().

Check failure on line 113 in src/FormElement/FieldsetElement.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Call to an undefined method ipl\Html\Contract\FormElement::isMultiple().

Check failure on line 113 in src/FormElement/FieldsetElement.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

Call to an undefined method ipl\Html\Contract\FormElement::isMultiple().

Check failure on line 113 in src/FormElement/FieldsetElement.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.0 on ubuntu-latest

Call to an undefined method ipl\Html\Contract\FormElement::isMultiple().

Check failure on line 113 in src/FormElement/FieldsetElement.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.1 on ubuntu-latest

Call to an undefined method ipl\Html\Contract\FormElement::isMultiple().

Check failure on line 113 in src/FormElement/FieldsetElement.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.2 on ubuntu-latest

Call to an undefined method ipl\Html\Contract\FormElement::isMultiple().

Check failure on line 113 in src/FormElement/FieldsetElement.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 8.3 on ubuntu-latest

Call to an undefined method ipl\Html\Contract\FormElement::isMultiple().
}

// TODO: I fear that nested fieldsets suffer from the same issue

/**
* We don't change the {@see BaseFormElement::$name} property of the element,
* otherwise methods like {@see FormElements::populate() and {@see FormElements::getElement()} would fail,
* but only change the name attribute to nest the names.
*/
return sprintf(
'%s[%s]',
'%s[%s]%s',
$this->getValueOfNameAttribute(),
$element->getName()
$element->getName(),
$multiple ? '[]' : ''
);
});
}
Expand Down

0 comments on commit d212a43

Please sign in to comment.