diff --git a/src/Container.php b/src/Container.php index 8bbc265..1adebf1 100644 --- a/src/Container.php +++ b/src/Container.php @@ -20,6 +20,8 @@ class Container extends \Nette\Forms\Container private ?string $wrapClass = null; + private array $dividerArray = []; + public function setId(string $id): self { @@ -258,6 +260,20 @@ public function addWhisperer(string $name, $label = null, array $items = []): Co } + public function addDivider(Html|string $content, ?string $previousControl = null): void + { + if(!$previousControl) + { + $controlArray = iterator_to_array($this->getControls()); + $lastControl = end($controlArray); + + $previousControl = $lastControl->getName(); + } + + $this->dividerArray[$previousControl] = $content; + } + + public function render(): string|Html { $components = $this->getComponents(); @@ -289,6 +305,11 @@ public function render(): string|Html foreach($inputArray as $control) { $inputs .= $control->render(); + + if(array_key_exists($control->getName(), $this->dividerArray)) + { + $inputs .= $this->dividerArray[$control->getName()]; + } } $rowDiv = Html::el('div') @@ -336,6 +357,11 @@ public function render(): string|Html { \assert($control instanceof Control\Renderable); $inputs .= $control->render(); + + if(array_key_exists($control->getName(), $this->dividerArray)) + { + $inputs .= $this->dividerArray[$control->getName()]; + } } $rowDiv = Html::el('div') diff --git a/src/Form.php b/src/Form.php index 7372122..010e4c6 100644 --- a/src/Form.php +++ b/src/Form.php @@ -45,6 +45,8 @@ class Form extends UIForm private string $defaultInputWrapClass = 'mb-3 col-12'; + private array $dividerArray = []; + public function __construct(\Nette\ComponentModel\IContainer $parent = null, $name = null) { @@ -93,6 +95,11 @@ public function renderForm() * Nette form hidden input */ $inputs .= $input instanceof \Nette\Forms\Controls\HiddenField ? $input->getControl() : $input->render(); + + if(array_key_exists($input->getName(), $this->dividerArray)) + { + $inputs .= $this->dividerArray[$input->getName()]; + } } if($inputs === null) @@ -108,18 +115,18 @@ public function renderForm() ->class('card-body') ->setHtml($row); - $carHeader = null; + $cardHeader = null; if($groupTitle || $this->getTitle()) { $groupColor = $group->getOption('color') ? ' ' . $group->getOption('color') : null; - $carHeader = Html::el('div') + $cardHeader = Html::el('div') ->class('card-header' . $groupColor) ->setHtml($groupTitle ?: $this->getTitle()); } - $content = $carHeader . $cardBody; + $content = $cardHeader . $cardBody; /** * Last iteration - add footer with submitters @@ -441,6 +448,20 @@ public function addMultiWhisperer(string $name, $label = null, array $items = nu } + public function addDivider(Html|string $content, ?string $previousControl = null): void + { + if(!$previousControl) + { + $controlArray = iterator_to_array($this->getControls()); + $lastControl = end($controlArray); + + $previousControl = $lastControl->getName(); + } + + $this->dividerArray[$previousControl] = $content; + } + + public function setRenderInline(bool $renderInline = true): self { $this->renderInline = $renderInline;