forked from foowie/DynamicFormContainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
69 lines (51 loc) · 2.17 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Dynamic Form Container
----------------------
Nette addon that allows dynamically add/remove set of items in Form
@author Daniel Robenek
@license MIT
class DynamicContainerCore - Base of functionality, allow to create dynamic container, add / remove row
class DynamicContainer - Extending DynamicContainerCore, added options for auto-create add and remove buttons
class FormMacros - Class created by Jan Marek, but upgraded to better functionality and implements DynamicContainer rendering
Example of DynamicContainer:
* Presenter *
<?php
protected function startup() {
parent::startup();
Addons\Forms\FormMacros::register(); // register form macros
Addons\Forms\DynamicContainer::register(); // register $form->addDynamicContainer($name);
}
public function createComponentForm($name) {
$form = new AppForm($this, $name);
$dynamicContainer = $form->addDynamicContainer("dynamicContainer");
// set button options not neccessery / have to be set befor form attached & factory set
$dynamicContainer->setAddButton(true, "Give me new row !", "addButtonOfDynamicContainer");
// set button options not neccessery / have to be set befor form attached & factory set
$dynamicContainer->setDeleteButton(true, "I dont wana this !", "removeButtonOfDynamicContainer");
$dynamicContainer->setMinCount(1); // minimum count of rows
$dynamicContainer->setMaxCount(5); // maximum count of rows
$dynamicContainer->setDefaultCount(2); // default count of rows
// set factory which add content to each of container
$dynamicContainer->setFactory(function(FormContainer $container) {
$container->addText("text", "Input")
->addRule(Form::FILLED, "Input must be fillet !");
$container->addCheckbox("isok", "Is it ok?");
});
return $form;
}
public function renderDefault() {
$this["form"]["dynamicContainer"]->beforeRender(); // needed :(
}
?>
* template (w/o formatting tags) *
<?php
{form form}
{formErrors 'li style="color: red"', 'ul style="font-size: 1.5em"'}
{input addButtonOfDynamicContainer}
{dynamicContainer dynamicContainer}
{label text}{input text}
{label isok}{input isok}
{input removeButtonOfDynamicContainer}
{/dynamicContainer}
{/form}
?>
Enjoy :)