Skip to content

Commit c0d9eec

Browse files
committed
Form: fixed calling setMethod() after 8df9520
1 parent 9f800e4 commit c0d9eec

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"require-dev": {
2929
"nette/tester": "~1.3",
30+
"nette/forms": "~2.2",
3031
"latte/latte": "~2.2.2"
3132
},
3233
"conflict": {

src/Application/UI/Form.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ protected function attached($presenter)
6868
$this->getElementPrototype()->id = 'frm-' . $name;
6969
}
7070

71-
if (!$this->getAction()) {
72-
$this->setAction(new Link($presenter, 'this', array()));
73-
$signal = new Nette\Forms\Controls\HiddenField($name . self::NAME_SEPARATOR . 'submit');
74-
$signal->setOmitted()->setHtmlId(FALSE);
75-
$this[Presenter::SIGNAL_KEY] = $signal;
76-
}
77-
7871
if (iterator_count($this->getControls()) && $this->isSubmitted()) {
7972
foreach ($this->getControls() as $control) {
8073
if (!$control->isDisabled()) {
8174
$control->loadHttpData();
8275
}
8376
}
8477
}
78+
79+
if (!$this->getAction()) {
80+
$this->setAction(new Link($presenter, 'this', array()));
81+
$signal = new Nette\Forms\Controls\HiddenField($name . self::NAME_SEPARATOR . 'submit');
82+
$signal->setOmitted()->setHtmlId(FALSE);
83+
$this[Presenter::SIGNAL_KEY] = $signal;
84+
}
8585
}
8686
parent::attached($presenter);
8787
}

tests/Application/Form.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Application\UI\Form
5+
*/
6+
7+
use Nette\Application\UI,
8+
Tester\Assert;
9+
10+
11+
require __DIR__ . '/../bootstrap.php';
12+
13+
14+
class TestPresenter extends UI\Presenter
15+
{
16+
17+
}
18+
19+
20+
test(function() {
21+
$presenter = new TestPresenter;
22+
$form = new UI\Form($presenter, 'name');
23+
$form->setMethod($form::GET); // must not throw exception
24+
});
25+
26+
27+
test(function() { // compatibility with 2.0
28+
$presenter = new TestPresenter;
29+
$form = new UI\Form;
30+
$form->setAction('action');
31+
$presenter['name'] = $form;
32+
Assert::false(isset($form[TestPresenter::SIGNAL_KEY]));
33+
});

0 commit comments

Comments
 (0)