Nette\Application\UI\BadSignalException: There is no handler for signal ‚submit‘ in class
- ondraondra81
- Člen | 82
Ahoj dostávám tuto hlášku při spuštění testu
Nette\Application\UI\BadSignalException: There is no handler for signal
‚submit‘ in class App\Components\Forms\UserLoginForm
můžete mě poradit kde mám chybu?
respektive chyba je asi tady ** ‚do‘ ⇒ ‚loginForm-submit‘,** ale
nějkak nevim co tam má být
testovaci funkce
public function testLoginForm() {
$presenter = $this->tester->getPresenter();
$response = $this->tester->test('default', 'POST', array(
'do' => 'loginForm-submit',
), array(
'username' => 'Username',
'password' => 'Password',
'remember' => TRUE,
));
Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse);
Tester\Assert::false($presenter->user->isLoggedIn());
$response = $this->tester->test('default', 'POST', array(
'do' => 'loginForm-submit',
), array(
'username' => 'Username',
'password' => 'Password',
'remember' => FALSE,
));
Tester\Assert::true($response instanceof Nette\Application\Responses\TextResponse);
Tester\Assert::false($presenter->user->isLoggedIn());
}
vytvoření komponenty v presentru LoginPresenter
/**
* @var IUserSignUpForm
*/
private $loginForm;
/**
* @param IUserLoginForm $loginForm
*/
public function injectLoginForm(IUserLoginForm $loginForm)
{
$this->loginForm = $loginForm;
}
/**
* @return UserLoginForm
*/
public function createComponentLoginForm()
{
return $this->loginForm->create();
}
komponta
public function createComponentForm()
{
$form = new UI\Form();
$form->addText('username', 'Uživatelské jméno:')
->addRule(UI\Form::FILLED, 'Musíte vyplnit uživatelské jméno!');
$form->addPassword('password', 'Heslo:')
->addRule(UI\Form::FILLED, 'Nezadali jste heslo');
$form->addCheckbox('remember', 'Zapamatovat');
$form->addSubmit('send', 'Přihlásit se');
$form = FormToBootstrap::setRender($form);
$form->onSuccess[] = $this->loginFormSucceeded;
return $form;
}
Editoval ondraondra81 (5. 9. 2014 14:18)
- David Matějka
- Moderator | 6445
ten form mas totiz zanoren pod komponentou – spravny signal
je loginForm-form-submit
- motorcb
- Člen | 552
matej21 napsal(a):
Jak je to s akcí do když volám klasickou komponentu?
protected function createComponentMyForm()
{
$form = new Form();
$form->addText( 'value', 'Value:' );
$form->addSubmit( 'send', 'Send' );
$form->onSuccess[] = $this->myFormSubmitted;
return $form;
}
{control myForm}
?
- David Matějka
- Moderator | 6445
@motorcb vzdycky je to
cesta-ke-komponente-ve-stromu-submit
, pokud mas tedy tohle primo
v presenteru, bude to myForm-submit
Editoval matej21 (5. 9. 2014 15:26)
- ondraondra81
- Člen | 82
Když se koukneš do zdrojového html kde máš ten formulář na odesílací
tlačítko
tak je tam např: frm-loginForm-form-send akce do je to bez
toho frm- a -send (název v addSubmit)
- motorcb
- Člen | 552
@ondraondra81:
Stále se mi to nedaří…
Mám Homepagepresenter:
<?php
namespace App\Presenters;
use Nette\Forms\Form;
class HomepagePresenter extends BasePresenter
{
protected function createComponentMyForm()
{
$form = new Form();
$form->addText( 'value', 'Value:' );
$form->addSubmit( 'send', 'Send' );
$form->onSuccess[] = $this->myFormSubmitted;
return $form;
}
public function myFormSubmitted( $form )
{
//dump( $form->name );
$this->flashMessage( 'Send...', "alert-success" );
$this->redirect( 'this' );
}
}
latte sablona default.latte pro presenter Homepage:
{block content}
{control myForm}
{/block}
A test:
function testForm()
{
$presenterFactory = $this->container->getByType( 'Nette\Application\IPresenterFactory' );
$presenter = $presenterFactory->createPresenter( 'Homepage' );
$presenter->autoCanonicalize = FALSE;
$request = new Nette\Application\Request( 'Homepage', 'POST', array(
'action' => 'default',
'do' => "myForm"
), array (
'value' => 'Testing value',
'send' => 'Send'
) );
$response = $presenter->run( $request );
Assert::type( "Nette\Application\Responses\RedirectResponse", $response );
}
Dostávám tuto chybu:
-- FAILED: nette\tests\HomepageTest.phpt
Exited with error code 255 (expected 0)
Nette\Application\UI\BadSignalException: There is no handler for signal 'myForm' in class App\Presenters\HomepagePresenter.
Jak na to?
- jiri.pudil
- Nette Blogger | 1029
Form
musí být Nette\Application\UI\Form
, ne
Nette\Forms\Form
.
Edit: a v signálu (do
) ti chybí submit:
myForm-submit
Editoval jiri.pudil (9. 9. 2014 10:58)