Skip to content

Commit 67b1889

Browse files
committed
examples: bootstrap updated
1 parent 1064f08 commit 67b1889

File tree

3 files changed

+45
-51
lines changed

3 files changed

+45
-51
lines changed

examples/bootstrap2-rendering.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,21 @@ function makeBootstrap2(Form $form)
3030
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-inline';
3131
$form->getElementPrototype()->class('form-horizontal');
3232

33-
$form->onRender[] = function ($form) {
34-
foreach ($form->getControls() as $control) {
35-
$type = $control->getOption('type');
36-
if ($type === 'button') {
37-
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn');
38-
$usedPrimary = true;
39-
40-
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
41-
$control->getSeparatorPrototype()->setName('div')->addClass($type);
42-
}
33+
foreach ($form->getControls() as $control) {
34+
$type = $control->getOption('type');
35+
if ($type === 'button') {
36+
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn');
37+
$usedPrimary = true;
38+
39+
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
40+
$control->getSeparatorPrototype()->setName('div')->addClass($type);
4341
}
44-
};
42+
}
4543
}
4644

4745

4846
$form = new Form;
49-
makeBootstrap2($form);
47+
$form->onRender[] = 'makeBootstrap2';
5048

5149
$form->addGroup('Personal data');
5250
$form->addText('name', 'Your name')

examples/bootstrap3-rendering.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,24 @@ function makeBootstrap3(Form $form)
3030
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
3131
$form->getElementPrototype()->class('form-horizontal');
3232

33-
$form->onRender[] = function ($form) {
34-
foreach ($form->getControls() as $control) {
35-
$type = $control->getOption('type');
36-
if ($type === 'button') {
37-
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
38-
$usedPrimary = true;
39-
40-
} elseif (in_array($type, ['text', 'textarea', 'select'], true)) {
41-
$control->getControlPrototype()->addClass('form-control');
42-
43-
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
44-
$control->getSeparatorPrototype()->setName('div')->addClass($type);
45-
}
33+
foreach ($form->getControls() as $control) {
34+
$type = $control->getOption('type');
35+
if ($type === 'button') {
36+
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-default');
37+
$usedPrimary = true;
38+
39+
} elseif (in_array($type, ['text', 'textarea', 'select'], true)) {
40+
$control->getControlPrototype()->addClass('form-control');
41+
42+
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
43+
$control->getSeparatorPrototype()->setName('div')->addClass($type);
4644
}
47-
};
45+
}
4846
}
4947

5048

5149
$form = new Form;
52-
makeBootstrap3($form);
50+
$form->onRender[] = 'makeBootstrap3';
5351

5452
$form->addGroup('Personal data');
5553
$form->addText('name', 'Your name')

examples/bootstrap4-rendering.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,33 @@ function makeBootstrap4(Form $form)
2929
$renderer->wrappers['control']['description'] = 'span class=form-text';
3030
$renderer->wrappers['control']['errorcontainer'] = 'span class=form-control-feedback';
3131

32-
$form->onRender[] = function ($form) {
33-
foreach ($form->getControls() as $control) {
34-
$type = $control->getOption('type');
35-
if ($type === 'button') {
36-
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-secondary');
37-
$usedPrimary = true;
38-
39-
} elseif (in_array($type, ['text', 'textarea', 'select'], true)) {
40-
$control->getControlPrototype()->addClass('form-control');
41-
42-
} elseif ($type === 'file') {
43-
$control->getControlPrototype()->addClass('form-control-file');
44-
45-
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
46-
if ($control instanceof Nette\Forms\Controls\Checkbox) {
47-
$control->getLabelPrototype()->addClass('form-check-label');
48-
} else {
49-
$control->getItemLabelPrototype()->addClass('form-check-label');
50-
}
51-
$control->getControlPrototype()->addClass('form-check-input');
52-
$control->getSeparatorPrototype()->setName('div')->addClass('form-check');
32+
foreach ($form->getControls() as $control) {
33+
$type = $control->getOption('type');
34+
if ($type === 'button') {
35+
$control->getControlPrototype()->addClass(empty($usedPrimary) ? 'btn btn-primary' : 'btn btn-secondary');
36+
$usedPrimary = true;
37+
38+
} elseif (in_array($type, ['text', 'textarea', 'select'], true)) {
39+
$control->getControlPrototype()->addClass('form-control');
40+
41+
} elseif ($type === 'file') {
42+
$control->getControlPrototype()->addClass('form-control-file');
43+
44+
} elseif (in_array($type, ['checkbox', 'radio'], true)) {
45+
if ($control instanceof Nette\Forms\Controls\Checkbox) {
46+
$control->getLabelPrototype()->addClass('form-check-label');
47+
} else {
48+
$control->getItemLabelPrototype()->addClass('form-check-label');
5349
}
50+
$control->getControlPrototype()->addClass('form-check-input');
51+
$control->getSeparatorPrototype()->setName('div')->addClass('form-check');
5452
}
55-
};
53+
}
5654
}
5755

5856

5957
$form = new Form;
60-
makeBootstrap4($form);
58+
$form->onRender[] = 'makeBootstrap4';
6159

6260
$form->addGroup('Personal data');
6361
$form->addText('name', 'Your name')
@@ -99,7 +97,7 @@ function makeBootstrap4(Form $form)
9997
<meta charset="utf-8">
10098
<title>Nette Forms & Bootstrap v4 rendering example</title>
10199

102-
<link rel="stylesheet" href="http://v4-alpha.getbootstrap.com/dist/css/bootstrap.min.css">
100+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
103101

104102
<div class="container">
105103
<h1>Nette Forms & Bootstrap v4 rendering example</h1>

0 commit comments

Comments
 (0)