/** * @param bool $ownOnly - true = render only global errors, false = render all errors of all controls * @return Html */ public function renderGlobalErrors($ownOnly = TRUE) { $errors = $ownOnly ? $this->form->getOwnErrors() : $this->form->getErrors(); $container = clone $this->prototypes->getGlobalErrors(); foreach ($errors as $error) { $alert = clone $this->prototypes->getGlobalError(); $this->addContent($alert->getPlaceholder(), $error); $container->getPlaceholder()->addHtml($alert); } return $container; }
/** * @return array */ public function findErrors() { $formErrors = $this->errorsAtInputs ? $this->form->getOwnErrors() : $this->form->getErrors(); if (!$formErrors) { return array(); } $form = $this->form; $translate = function ($errors) use($form) { if ($translator = $form->getTranslator()) { // If we have translator, translate! foreach ($errors as $key => $val) { $errors[$key] = $translator->translate($val); } } return $errors; }; return $translate($formErrors); }
/** * Renders validation errors (per form or per control). * @return string */ public function renderErrors(Nette\Forms\IControl $control = NULL, $own = TRUE) { $errors = $control ? $control->getErrors() : ($own ? $this->form->getOwnErrors() : $this->form->getErrors()); if (!$errors) { return; } $container = $this->getWrapper($control ? 'control errorcontainer' : 'error container'); $item = $this->getWrapper($control ? 'control erroritem' : 'error item'); foreach ($errors as $error) { $item = clone $item; if ($error instanceof Html) { $item->add($error); } else { $item->setText($error); } $container->add($item); } return "\n" . $container->render($control ? 1 : 0); }