Multiplier, replicator for nette forms
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Reset form events after removeAction Oct 16, 2018
tests added test for issue #32 Aug 1, 2018
.gitignore
.travis.yml dropped hhvm Jun 18, 2018
README.md addRemoveButton returns builder Jun 20, 2018
codeception.yml
composer.json phpunit/phpunit added lower versions Aug 1, 2018

README.md

Multiplier, replication for Nette\Forms

Build Status

Installation

composer require webchemistry/forms-multiplier
extensions:
    - WebChemistry\Forms\Controls\DI\MultiplierExtension

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');

Adding multiple containers

$multiplier->addCreateButton('Add'); // add one container
$multiplier->addCreateButton('Add 5', 5); // add five containers

Macros

{form multiplier}
	<div n:multiplier="multiplier">
		<input n:name="text">
		{btnRemove 'class' => 'myClass'}
	</div>
	{btnCreate multiplier class => myClass}
	{btnCreate $form[multiplier]:5}
{/form}