Skip to content

Configuration reference ​

The renderers have one constructor option and the public $wrappers array. There is nothing to register in a DI container and no global state.

Constructor ​

php
use Tomaj\Form\Renderer\BootstrapInlineRenderer;
use Tomaj\Form\Renderer\BootstrapRenderer;
use Tomaj\Form\Renderer\BootstrapVerticalRenderer;

$horizontal = new BootstrapRenderer();
$vertical = new BootstrapVerticalRenderer(novalidate: true);
$inline = new BootstrapInlineRenderer(novalidate: false);
ParameterTypeDefaultMeaning
$novalidatebooltrueAdd novalidate="novalidate" to the <form> element, so the browser skips its HTML5 validation and Nette's validation shows the errors. false keeps the browser validation. See HTML5 validation.

The value is a private readonly property: it cannot be changed after the renderer is created.

$wrappers ​

public array $wrappers, the same array as in Nette\Forms\Rendering\DefaultFormRenderer, with values for Bootstrap 3. A value is an element definition for Nette\Utils\Html::el() (div class=col-sm-9, div class="col-sm-3 control-label"), a class name (keys starting with a dot), a text (suffix, requiredsuffix), or null/'' for "nothing". Change it on the instance before rendering:

php
use Tomaj\Form\Renderer\BootstrapRenderer;

$renderer = new BootstrapRenderer();
$renderer->wrappers['control']['container'] = 'div class=col-sm-8';
One label and control pair of BootstrapRenderer: div.form-group (pair container, with required and has-error from pair .required and pair .error) holds div.col-sm-3.control-label (label container) around the label, and div.col-sm-9 (control container) around the input, the description help-block and the error help-block.One label and control pair of BootstrapRenderer: div.form-group (pair container, with required and has-error from pair .required and pair .error) holds div.col-sm-3.control-label (label container) around the label, and div.col-sm-9 (control container) around the input, the description help-block and the error help-block.

In the tables, H is BootstrapRenderer (horizontal), V BootstrapVerticalRenderer and I BootstrapInlineRenderer. Where the three values are the same, there is one.

form ​

KeyHVIMeaning
containernullnull''Element around everything inside <form> (groups, pairs). The <form> element itself is $form->getElementPrototype().

error ​

Errors of the form itself, rendered above the controls (and all errors in the errors mode).

KeyValueMeaning
containerdiv class="alert alert-danger"Element around the list of errors.
itempElement of one error.

group ​

Used for $form->addGroup().

KeyValueMeaning
containerfieldsetElement around a group. A group can override it with setOption('container', ...).
labellegendElement of the group label (addGroup('Label')).
descriptionpElement of the group description (setOption('description', ...) on the group).

controls ​

KeyHVIMeaning
containerdivnull''Element around the pairs of the form or of one group.

pair ​

One label and its control (or a row of buttons).

KeyValueMeaning
containerdiv class=form-groupElement around the label and the control.
.requiredrequiredClass of the pair when the control is required.
.optionalnullClass of the pair when the control is optional.
.oddnullClass of every odd pair (for striped forms).
.errorhas-errorClass of the pair when the control has an error.

control ​

KeyHVIMeaning
containerdiv class=col-sm-9''nullElement around the control, its description and its errors.
.oddnullClass of the control container in odd pairs.
descriptionspan class=help-blockElement of a string description (setOption('description', ...)).
requiredsuffix''Text added after a required control, before its description.
errorcontainerspan class=help-blockElement around the errors of a control.
erroritem''Element of one control error; empty means the errors are joined in the container.
.requiredrequiredClass of the <label> of a required control.
.texttextClass added to <input type="text">.
.passwordtextClass added to <input type="password">.
.filetextClass added to <input type="file">.
.submitbuttonClass added to <input type="submit">.
.imageimagebuttonClass added to <input type="image">.
.buttonbuttonClass added to <input type="button">.

DefaultFormRenderer reads a few more control keys that the Bootstrap renderers do not define, so they are null (nothing) unless you set them: .error (class of a control with errors), .multi (class of a control container holding several controls via the nextTo option) and .email, .number (class of those input types; Nette's own renderer sets text there).

label ​

KeyHVIMeaning
containerdiv class="col-sm-3 control-label"''''Element around the <label>.
suffixnullText appended to every label.
requiredsuffix''Text appended to the label of a required control, for example ' *'.

hidden ​

KeyValueMeaning
containerdivElement around the hidden fields, rendered just before </form>.

Classes added outside $wrappers ​

These are added by the renderer's own code before rendering, and are not configurable through $wrappers:

WhereClassWhen
<form>form-horizontal (H), form-inline (I)always, next to existing classes
<form>novalidate="novalidate" attributeunless created with novalidate: false
text inputs, text areas, selects, multi-selectsform-controlalways
buttonsbtn btn-primary / btn btn-defaultunless the class already contains btn
checkboxits label in div.checkboxalways
checkbox list, radio listeach item in div.checkbox / div.radioalways

To change one of these for a control, set the class on the control yourself (a button with btn in its class is left alone), or wrap the renderer (Customizing).

Released under the MIT License.