Contributte Forms-multiplier
# Contributte\Form-multiplier
# Content
# Usage
# Register extension
extensions:
- Contributte\FormMultiplier\DI\MultiplierExtension
1
2
2
# Basic usage
$form = new Nette\Forms\Form;
$copies = 1;
$maxCopies = 10;
$multiplier = $form->addMultiplier('multiplier', function (Nette\Forms\Container $container, Nette\Forms\Form $form) {
$container->addText('text', 'Text')
->setDefaultValue('My value');
}, $copies, $maxCopies);
$multiplier->addCreateButton('Add')
->addClass('btn btn-primary');
$multiplier->addRemoveButton('Remove')
->addClass('btn btn-danger');
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# Adding multiple containers
$multiplier->addCreateButton('Add'); // add one container
$multiplier->addCreateButton('Add 5', 5); // add five containers
1
2
2
# Macros
{form multiplier}
<div n:multiplier="multiplier">
<input n:name="text">
{multiplier:remove class: myClass}
</div>
{multiplier:add multiplier class: myClass}
{multiplier:add multiplier:5}
{/form}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9