diff --git a/examples/bootstrap4-rendering.php b/examples/bootstrap4-rendering.php index b4ee008e2..853a5da3c 100644 --- a/examples/bootstrap4-rendering.php +++ b/examples/bootstrap4-rendering.php @@ -28,6 +28,7 @@ function makeBootstrap4(Form $form): void $renderer->wrappers['label']['container'] = 'div class="col-sm-3 col-form-label"'; $renderer->wrappers['control']['description'] = 'span class=form-text'; $renderer->wrappers['control']['errorcontainer'] = 'span class=form-control-feedback'; + $renderer->wrappers['control']['.error'] = 'is-invalid'; foreach ($form->getControls() as $control) { $type = $control->getOption('type'); diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index 6838da0fc..542dae929 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -47,7 +47,7 @@ class DefaultFormRenderer implements Nette\Forms\IFormRenderer * \--- * * /--- control.container [.odd] - * .... CONTROL [.required .text .password .file .submit .button] + * .... CONTROL [.required .error .text .password .file .submit .button] * .... control.requiredsuffix * .... control.description * .... control.errorcontainer + control.erroritem @@ -95,6 +95,7 @@ class DefaultFormRenderer implements Nette\Forms\IFormRenderer 'erroritem' => '', '.required' => 'required', + '.error' => null, '.text' => 'text', '.password' => 'text', '.file' => 'text', @@ -386,8 +387,12 @@ public function renderPairMulti(array $controls): string $control->setOption('rendered', true); $el = $control->getControl(); - if ($el instanceof Html && $el->getName() === 'input') { - $el->class($this->getValue("control .$el->type"), true); + if ($el instanceof Html) { + if ($el->getName() === 'input') { + $el->class($this->getValue("control .$el->type"), true); + } + + $el->class($this->getValue('control .error'), $control->hasErrors()); } $s[] = $el . $description; } @@ -447,8 +452,12 @@ public function renderControl(Nette\Forms\IControl $control): Html $control->setOption('rendered', true); $el = $control->getControl(); - if ($el instanceof Html && $el->getName() === 'input') { - $el->class($this->getValue("control .$el->type"), true); + if ($el instanceof Html) { + if ($el->getName() === 'input') { + $el->class($this->getValue("control .$el->type"), true); + } + + $el->class($this->getValue('control .error'), $control->hasErrors()); } return $body->setHtml($el . $description . $this->renderErrors($control)); } diff --git a/tests/Forms/Forms.renderer.2.expect b/tests/Forms/Forms.renderer.2.expect index 0977c3199..4c3367333 100644 --- a/tests/Forms/Forms.renderer.2.expect +++ b/tests/Forms/Forms.renderer.2.expect @@ -13,7 +13,7 @@
-