Skip to content

Instantly share code, notes, and snippets.

@jtojnar
Created March 20, 2024 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtojnar/0c059c4b1671a9c7348d641a2578445d to your computer and use it in GitHub Desktop.
Save jtojnar/0c059c4b1671a9c7348d641a2578445d to your computer and use it in GitHub Desktop.
application:
scanDirs: false
mapping:
*: ContributteDemos\FormMultiplier\*Presenter
extensions:
- Contributte\FormMultiplier\DI\MultiplierExtension
services:
routing.router: Nette\Application\Routers\SimpleRouter('Examples:default')
<!DOCTYPE html>
<html lang="en">
<head>
<title>Multiplier demo</title>
</head>
<body>
<div class="container">
<h1>Contributte Form Multiplier</h1>
{form form}
<div n:multiplier="emails">
<input n:name="email" />
</div>
{multiplier:add emails class: myClass}
{multiplier:add emails:5}
{/form}
</div>
</body>
</html>
<?php declare(strict_types = 1);
namespace ContributteDemos\FormMultiplier;
use Nette\Application\UI\Form;
use Nette\Application\UI\Presenter;
use Nette\Forms\Container;
use Contributte\FormMultiplier\Multiplier;
class ExamplesPresenter extends Presenter
{
private Form $form;
public function renderDefault()
{
}
public function createComponentForm()
{
$this->form = $form = new Form();
$emails = $this->form->addMultiplier('emails', function(Container $container): void {
$container->addText('email', 'Email');
});
$emails->addCreateButton('Add');
$emails->addRemoveButton('Remove');
$form->onSuccess[] = function ($form, $values) {
dump($values);
};
return $form;
}
public function formatTemplateFiles(): array
{
return [__DIR__ . '/ExamplesPresenter.latte'];
}
}
<?php declare(strict_types = 1);
namespace ContributteDemos\FormMultiplier;
use Nette\Application\Application;
use Nette\Configurator;
require_once __DIR__ . '/../vendor/autoload.php';
$configurator = new Configurator;
// $configurator->setDebugMode(false);
$configurator->enableTracy(__DIR__ . '/log');
$configurator->setTempDirectory(__DIR__ . '/temp');
$configurator->createRobotLoader()->addDirectory(__DIR__)->register();
$configurator->addConfig(__DIR__ . '/config.neon');
$container = $configurator->createContainer();
$app = $container->getByType(Application::class);
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment