DependentSelectBoxdev – Component with name ‚TestForm‘ does not exist
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- Desttro
- Člen | 126
Zdravím,
našel jsem si tento návod https://componette.org/search/?…
všechno zkopíruju a vždy mi nette vyhodí: Nette\InvalidArgumentException,
Component with name ‚TestForm‘ does not exist.
Nechápu proč, když definovaný je, potřebuju aby byl funkční ajax a
funkční filtrování, zkouším to furt dokola a furt si nevím rady. Prosím,
pomohl by mi někdo? Děkuji moc.
moje soubory:
bootstrap.php
<?php
require __DIR__ . '/../vendor/autoload.php';
$configurator = new Nette\Configurator;
$configurator->setDebugMode(TRUE); // debug mode MUST NOT be enabled on production server
$configurator->enableDebugger(__DIR__ . '/../log');
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->createRobotLoader()
->addDirectory(__DIR__)
->addDirectory(__DIR__ . '/../vendor/others')
->register();
$configurator->addConfig(__DIR__ . '/config/config.neon');
$configurator->addConfig(__DIR__ . '/config/config.local.neon');
$container = $configurator->createContainer();
\DependentSelectBox\DependentSelectBox::register(); // First parameter of this method denotes name of method to add selectbox into form. Default name is addDependentSelectBox, but short name like addDSelect can be used.
\DependentSelectBox\JsonDependentSelectBox::register();
return $container;
@layout.latte
{**
* @param string $basePath web base path
* @param array $flashes flash messages
*}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{ifset #title}{include title|striptags} | {/ifset}Nette Sandbox</title>
<link rel="stylesheet" media="screen,projection,tv" href="{$basePath}/css/screen.css">
<link rel="stylesheet" media="print" href="{$basePath}/css/print.css">
<link rel="shortcut icon" href="{$basePath}/favicon.ico">
{block head}{/block}
</head>
<body>
<script> document.documentElement.className+=' js' </script>
<div n:foreach="$flashes as $flash" class="flash {$flash->type}">{$flash->message}</div>
{include content}
{block scripts}
<script src="{$basePath}/js/jquery.js"></script>
<script src="{$basePath}/js/dependentselectbox.ajax.js"></script>
<script src="{$basePath}/js/jquery.nette.dependentselectbox.js"></script>
<script src="{$basePath}/js/netteForms.js"></script>
<script src="{$basePath}/js/main.js"></script>
<script>
{/block}
</body>
</html>
BasePresenter.php
<?php
namespace App\Presenters;
use Nette,
App\Model;
/**
* Base presenter for all application presenters.
*/
abstract class BasePresenter extends Nette\Application\UI\Presenter
{
public function startup() {
parent::startup();
\DependentSelectBox\JsonDependentSelectBox::register('addJSelect');
}
public function beforeRender() {
parent::beforeRender();
\DependentSelectBox\JsonDependentSelectBox::tryJsonResponse($this /*(presenter)*/);
}
}
HomepagePresenter.php
<?php
namespace App\Presenters;
use Nette,
App\Model;
use Nette\Application\UI\Form;
class HomepagePresenter extends BasePresenter
{
/** * Select helper */
private function getCarModelsByType($form) {
$id = $form["car_type"]->value;
$array = $this->models->car->getModelsByType($id); // return array("key" => "name");
return $array; // array is required as return type
}
/** * Form */
protected function createComponentTestForm($name) {
$form = new Form($this, $name); // required for full running
$form->addSelect("car_type", "Car type", array("Opel", "Škoda", "BMW"));
$form->addJSelect("car_model","Model", $form["car_type"], array($this, "getCarModelsByType"));
$form->onSubmit[] = array($this, "testFormSent");
$form->addSubmit("submit", "Save");
return $form;
}
/** * Save form */
public function testFormSent(Form $form) {
if ($form["submit"]->isSubmittedBy()) {
// required to avoid submit form on select change
$values = $form->values;
// ...
}
}
}
templates/Homepage/default.latte
{block content}
{form TestForm}
{/form}
{/block}