1
|
<?php
|
2
|
|
3
|
|
4
|
namespace App\Utils;
|
5
|
|
6
|
|
7
|
/**
|
8
|
* Slouží k vytváření formulářů s bootstrapovým vzhledem
|
9
|
*
|
10
|
* @package App\Utils
|
11
|
*/
|
12
|
class Form extends \Nette\Application\UI\Form
|
13
|
{
|
14
|
public function __construct($name = null)
|
15
|
{
|
16
|
parent::__construct($name);
|
17
|
|
18
|
$renderer = $this->getRenderer();
|
19
|
$renderer->wrappers['controls']['container'] = null;
|
20
|
$renderer->wrappers['pair']['container'] = 'div class="row mt-2"';
|
21
|
$renderer->wrappers['pair']['.error'] = 'has-error';
|
22
|
$renderer->wrappers['control']['container'] = 'div class=col-8';
|
23
|
$renderer->wrappers['label']['container'] = 'div class="col-4 control-label"';
|
24
|
$renderer->wrappers['control']['description'] = 'span class=help-block';
|
25
|
$renderer->wrappers['error']['container'] = 'div class="alert alert-danger"';
|
26
|
$this->getElementPrototype()->class('form-horizontal');
|
27
|
|
28
|
}
|
29
|
|
30
|
public function addText($name, $label = null, $cols = null, $maxLength = null)
|
31
|
{
|
32
|
return parent::addText($name, $label, $cols, $maxLength)->setHtmlAttribute('class', 'form-control');
|
33
|
}
|
34
|
|
35
|
public function addSelect($name, $label = null, array $items = null, $size = null)
|
36
|
{
|
37
|
return parent::addSelect($name, $label, $items, $size)->setHtmlAttribute('class', 'form-control');
|
38
|
}
|
39
|
|
40
|
public function addPassword($name, $label = null, $cols = null, $maxLength = null)
|
41
|
{
|
42
|
return parent::addPassword($name, $label, $cols, $maxLength)->setHtmlAttribute('class', 'form-control');
|
43
|
}
|
44
|
|
45
|
public function addEmail($name, $label = null)
|
46
|
{
|
47
|
return parent::addEmail($name, $label)->setHtmlAttribute('class', 'form-control');
|
48
|
}
|
49
|
|
50
|
public function addTextArea($name, $label = null, $cols = null, $rows = null)
|
51
|
{
|
52
|
return parent::addTextArea($name, $label, $cols, $rows)->setHtmlAttribute('class', 'form-control');
|
53
|
}
|
54
|
|
55
|
public function addUpload($name, $label = null, $multiple = false)
|
56
|
{
|
57
|
return parent::addUpload($name, $label, $multiple)->setHtmlAttribute('class', 'form-control');
|
58
|
}
|
59
|
|
60
|
public function addInteger($name, $label = null)
|
61
|
{
|
62
|
return parent::addInteger($name, $label)->setHtmlAttribute('class', 'form-control');
|
63
|
}
|
64
|
|
65
|
protected function beforeRender()
|
66
|
{
|
67
|
parent::beforeRender();
|
68
|
|
69
|
foreach ($this->getControls() as $control)
|
70
|
{
|
71
|
$type = $control->getOption('type');
|
72
|
if ($type === 'button')
|
73
|
{
|
74
|
$control->getControlPrototype()->addClass('btn btn-success form-control');
|
75
|
}
|
76
|
}
|
77
|
}
|
78
|
}
|