/** * Determines which groups should be rendered (visual groups with at least one control). * * @return ControlGroup[] */ private function getGroupsToRender() { $groups = array_filter($this->form->getGroups(), function (ControlGroup $group) { return $group->getControls() && $group->getOption('visual'); }); return $groups; }
public function render(\Nette\Forms\Form $form, $mode = null) { $content = Html::el('div class="details"'); foreach ($form->getGroups() as $group) { if (!$group->getControls() || !$group->getOption('visual')) { continue; } $elgroup = $content->create('div class="viewGroup"'); $grouplabel = $group->getOption('label'); if (!is_string($grouplabel)) { $grouplabel = $grouplabel->getText(); } $elgroup->create('h5', $grouplabel); $el = $elgroup->create('dl'); foreach ($group->getControls() as $control) { if ($control instanceof \Nette\Forms\Controls\HiddenField || $control instanceof \Nette\Forms\Controls\Button) { continue; } $label = $control->getLabel(); if (!is_string($label)) { $label = $label->getText(); } $el->create('dt', $label); $value = $control->getValue(); if ($control instanceof \Nette\Forms\Controls\Checkbox) { if ($value) { $el->create('dd')->create('span class="yes"'); } else { $el->create('dd')->create('span class="no"'); } } elseif ($control instanceof \Nette\Forms\Controls\SelectBox) { $items = FlatArray::getLeafs($control->getItems()); if (!isset($items[$value])) { $el->create('dd class="na"', 'n/a'); continue; } $value = $items[$value]; if (!is_string($value)) { $value = $value->getTitle(); } $el->create('dd', $value); } else { if ($value instanceof \Nette\DateTime) { $value = $value->format('j.n.Y'); } if ($value !== '') { $el->create('dd', $value); } else { $el->create('dd class="na"', 'n/a'); } } } $elgroup->create('div style="{clear: both;}"'); } return $content; }
/** * Renders form body. * @return string */ public function renderBody() { $s = $remains = ''; $defaultContainer = $this->getWrapper('group container'); $translator = $this->form->getTranslator(); foreach ($this->form->getGroups() as $group) { if (!$group->getControls() || !$group->getOption('visual')) { continue; } $container = $group->getOption('container', $defaultContainer); $container = $container instanceof Html ? clone $container : Html::el($container); $id = $group->getOption('id'); if ($id) { $container->id = $id; } $s .= "\n" . $container->startTag(); $text = $group->getOption('label'); if ($text instanceof Html) { $s .= $this->getWrapper('group label')->add($text); } elseif (is_string($text)) { if ($translator !== NULL) { $text = $translator->translate($text); } $s .= "\n" . $this->getWrapper('group label')->setText($text) . "\n"; } $text = $group->getOption('description'); if ($text instanceof Html) { $s .= $text; } elseif (is_string($text)) { if ($translator !== NULL) { $text = $translator->translate($text); } $s .= $this->getWrapper('group description')->setText($text) . "\n"; } $s .= $this->renderControls($group); $remains = $container->endTag() . "\n" . $remains; if (!$group->getOption('embedNext')) { $s .= $remains; $remains = ''; } } $s .= $remains . $this->renderControls($this->form); $container = $this->getWrapper('form container'); $container->setHtml($s); return $container->render(0); }
public function render(\Nette\Forms\Form $form, $mode = null) { $content = Html::el('form')->action($form->action)->method($form->method); foreach ($form->getGroups() as $group) { if (!$group->getControls() || !$group->getOption('visual')) { continue; } $elgroup = $content->create('fieldset'); $grouplabel = $group->getOption('label'); if (!is_string($grouplabel)) { $grouplabel = $grouplabel->getText(); } $elgroup->create('legend', $grouplabel); $el = $elgroup->create('dl'); foreach ($group->getControls() as $control) { if ($control instanceof \Nette\Forms\Controls\HiddenField) { $el->add($control->getControl()); continue; } if ($control instanceof \Nette\Forms\Controls\Button) { $el->create('dt')->id($control->htmlId . '-dt'); $el->create('dd')->id($control->htmlId . '-dd')->add($control->getControl()); continue; } $label = $control->getLabel(); $el->create('dt')->id($control->htmlId . '-dt')->add($label); $dd = $el->create('dd')->id($control->htmlId . '-dd'); $dd->add($control->getControl()); if ($control->hasErrors()) { $dd->class('error'); $errors = $control->getErrors(); $dd->create('span class="error"'); $dd->create('', $control->errors[0]); } } $elgroup->create('div style="{clear: both;}"'); } return $content; }