From 2794ce1899f1dec524f5ca557777e3013e5fbce9 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sun, 16 Jul 2017 23:50:20 +0200 Subject: [PATCH 01/11] composer: updated description --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b19cfbbf3..630ef929d 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "nette/forms", - "description": "Nette Forms: greatly facilitates web forms", + "description": "?? Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server & client side validation and mature design.", + "keywords": ["nette", "forms", "validation", "csrf", "javascript", "bootstrap"], "homepage": "https://nette.org", "license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"], "authors": [ From 95e01700510302b057b3304f25b1ecd9ad512b95 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 13 Jul 2017 18:36:25 +0200 Subject: [PATCH 02/11] travis: tested using Nette Coding Standard --- .travis.yml | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 925312e61..da79801da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ matrix: env: dependencies="--prefer-lowest --prefer-stable" - php: 7.0 env: coverage=on + - php: 7.1 + env: codingStandard=on allow_failures: - php: 7.0 @@ -18,27 +20,36 @@ matrix: script: - vendor/bin/tester tests -s -c tests/php-unix.ini $coverageArgs - - php temp/code-checker/src/code-checker.php --short-arrays -i netteForms - - if [ $TRAVIS_PHP_VERSION == "7.0" ]; then grunt --gruntfile=tests/netteForms/Gruntfile.js test; fi + - > + if [ "$codingStandard" ]; then + php temp/code-checker/src/code-checker.php --short-arrays + && php temp/coding-standard/ecs check src tests examples --config temp/coding-standard/coding-standard-php56.neon + && grunt --gruntfile=tests/netteForms/Gruntfile.js test; + fi after_failure: # Print *.actual content - for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done before_script: - # Install Nette Tester & Code Checker + # Install Nette Tester - travis_retry composer update --no-interaction --prefer-dist $dependencies - - travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction - - if [ $TRAVIS_PHP_VERSION == "7.0" ]; then npm install -g grunt-cli; cd tests/netteForms; npm install; cd ../..; fi - - if [ "$coverage" == "on" ]; then coverageArgs="-p phpdbg --coverage ./coverage.xml --coverage-src ./src"; fi + # Install Code Checkers + - > + if [ "$codingStandard" ]; then + travis_retry composer create-project nette/code-checker temp/code-checker ~2 --no-interaction; + travis_retry composer create-project nette/coding-standard temp/coding-standard --no-interaction; + npm install -g grunt-cli; cd tests/netteForms; npm install; cd ../..; + fi + - if [ "$coverage" ]; then coverageArgs="-p phpdbg --coverage ./coverage.xml --coverage-src ./src"; fi after_script: # Report Code Coverage - > - if [ "$coverage" == "on" ]; then + if [ "$coverage" ]; then wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar - && php coveralls.phar --verbose --config tests/.coveralls.yml - || true; fi + && php coveralls.phar --verbose --config tests/.coveralls.yml; + fi sudo: false From 12e9b79a0b69bce50245f7542460f298cd0ce0a3 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 24 Jul 2017 02:51:50 +0200 Subject: [PATCH 03/11] travis: added PHP 7.2 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index da79801da..29073447b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ php: - 5.6 - 7.0 - 7.1 + - 7.2 env: matrix: From 1b47f93b26bcd8fc434b1e8ebb6ed91897753661 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 24 Jul 2017 15:04:14 +0200 Subject: [PATCH 04/11] travis: use stages --- .travis.yml | 81 ++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index 29073447b..cfff85217 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,55 +5,60 @@ php: - 7.1 - 7.2 -env: -matrix: - include: - - php: 5.6 - env: dependencies="--prefer-lowest --prefer-stable" - - php: 7.0 - env: coverage=on - - php: 7.1 - env: codingStandard=on +before_install: + # turn off XDebug + - phpenv config-rm xdebug.ini || return 0 - allow_failures: - - php: 7.0 - env: coverage=on +install: + - travis_retry composer install --no-progress --prefer-dist script: - - vendor/bin/tester tests -s -c tests/php-unix.ini $coverageArgs - - > - if [ "$codingStandard" ]; then - php temp/code-checker/src/code-checker.php --short-arrays - && php temp/coding-standard/ecs check src tests examples --config temp/coding-standard/coding-standard-php56.neon - && grunt --gruntfile=tests/netteForms/Gruntfile.js test; - fi + - vendor/bin/tester tests -s after_failure: # Print *.actual content - for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done -before_script: - # Install Nette Tester - - travis_retry composer update --no-interaction --prefer-dist $dependencies - # Install Code Checkers - - > - if [ "$codingStandard" ]; then - travis_retry composer create-project nette/code-checker temp/code-checker ~2 --no-interaction; - travis_retry composer create-project nette/coding-standard temp/coding-standard --no-interaction; - npm install -g grunt-cli; cd tests/netteForms; npm install; cd ../..; - fi - - if [ "$coverage" ]; then coverageArgs="-p phpdbg --coverage ./coverage.xml --coverage-src ./src"; fi - -after_script: - # Report Code Coverage - - > - if [ "$coverage" ]; then - wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar - && php coveralls.phar --verbose --config tests/.coveralls.yml; - fi +jobs: + include: + - env: title="Lowest Dependencies" + install: + - travis_retry composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable + + + - stage: Code Standard Checker + php: 7.1 + install: + # Install Nette Code Checker + - travis_retry composer create-project nette/code-checker temp/code-checker ~2 --no-progress + # Install Nette Coding Standard + - travis_retry composer create-project nette/coding-standard temp/coding-standard --no-progress + # Install Grunt + - npm install -g grunt-cli; cd tests/netteForms; npm install; cd ../.. + script: + - php temp/code-checker/src/code-checker.php --short-arrays + - php temp/coding-standard/ecs check src tests examples --config temp/coding-standard/coding-standard-php56.neon + - grunt --gruntfile=tests/netteForms/Gruntfile.js test + + + - stage: Code Coverage + php: 7.1 + script: + - vendor/bin/tester -p phpdbg tests -s --coverage ./coverage.xml --coverage-src ./src + after_script: + - wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar + - php coveralls.phar --verbose --config tests/.coveralls.yml + + + allow_failures: + - stage: Code Coverage + sudo: false cache: directories: - $HOME/.composer/cache + +notifications: + email: false From 389f849d63f5aaa3dc9f8db102b5b379689dd3a6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 24 Jul 2017 16:03:33 +0200 Subject: [PATCH 05/11] typo --- tests/Forms/Forms.submittedBy.phpt | 90 +++++++++++++++--------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/tests/Forms/Forms.submittedBy.phpt b/tests/Forms/Forms.submittedBy.phpt index 78c12660f..caaf286f4 100644 --- a/tests/Forms/Forms.submittedBy.phpt +++ b/tests/Forms/Forms.submittedBy.phpt @@ -1,45 +1,45 @@ - $name, 'send2' => '']; - - $form = new Form($name); - $btn1 = $form->addSubmit('send1'); - $btn2 = $form->addSubmit('send2'); - $btn3 = $form->addSubmit('send3'); - - Assert::true($form->isSuccess()); - Assert::same($btn2, $form->isSubmitted()); -}); - - -test(function () { - $name = 'name'; - $_POST = [Form::TRACKER_ID => $name, 'send2' => ['x' => 1, 'y' => 1]]; - - $form = new Form($name); - $btn1 = $form->addImage('send1'); - $btn2 = $form->addImage('send2'); - $btn3 = $form->addImage('send3'); - - Assert::true($form->isSuccess()); - Assert::same($btn2, $form->isSubmitted()); -}); + $name, 'send2' => '']; + + $form = new Form($name); + $btn1 = $form->addSubmit('send1'); + $btn2 = $form->addSubmit('send2'); + $btn3 = $form->addSubmit('send3'); + + Assert::true($form->isSuccess()); + Assert::same($btn2, $form->isSubmitted()); +}); + + +test(function () { + $name = 'name'; + $_POST = [Form::TRACKER_ID => $name, 'send2' => ['x' => 1, 'y' => 1]]; + + $form = new Form($name); + $btn1 = $form->addImage('send1'); + $btn2 = $form->addImage('send2'); + $btn3 = $form->addImage('send3'); + + Assert::true($form->isSuccess()); + Assert::same($btn2, $form->isSubmitted()); +}); From 72289ef7c1204d184d66c0668facab5b287eeed4 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 9 Aug 2017 17:28:06 +0200 Subject: [PATCH 06/11] coding style --- tests/Forms/Controls.TestBase.validators.phpt | 16 ++++++++-------- tests/Forms/Forms.callbackParameters.phpt | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Forms/Controls.TestBase.validators.phpt b/tests/Forms/Controls.TestBase.validators.phpt index fdc70c24b..390200c56 100644 --- a/tests/Forms/Controls.TestBase.validators.phpt +++ b/tests/Forms/Controls.TestBase.validators.phpt @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; test(function () { - $control = new TextInput(); + $control = new TextInput; $control->value = ''; Assert::true(Validator::validateMinLength($control, 0)); Assert::false(Validator::validateMinLength($control, 1)); @@ -21,7 +21,7 @@ test(function () { test(function () { - $control = new TextInput(); + $control = new TextInput; $control->value = ''; Assert::true(Validator::validateMaxLength($control, 0)); @@ -32,7 +32,7 @@ test(function () { test(function () { - $control = new TextInput(); + $control = new TextInput; $control->value = ''; Assert::true(Validator::validateLength($control, 0)); Assert::true(Validator::validateLength($control, [0, 0])); @@ -46,7 +46,7 @@ test(function () { test(function () { - $control = new TextInput(); + $control = new TextInput; $control->value = ''; Assert::false(Validator::validateEmail($control)); @@ -65,7 +65,7 @@ test(function () { test(function () { - $control = new TextInput(); + $control = new TextInput; $control->value = ''; Assert::false(Validator::validateUrl($control)); Assert::same('', $control->value); @@ -84,7 +84,7 @@ test(function () { test(function () { - $control = new TextInput(); + $control = new TextInput; $control->value = '123x'; Assert::false(Validator::validatePattern($control, '[0-9]')); Assert::true(Validator::validatePattern($control, '[0-9]+x')); @@ -93,7 +93,7 @@ test(function () { test(function () { - $control = new TextInput(); + $control = new TextInput; $control->value = ''; Assert::false(Validator::validateInteger($control)); Assert::same('', $control->value); @@ -117,7 +117,7 @@ test(function () { test(function () { - $control = new TextInput(); + $control = new TextInput; $control->value = ''; Assert::false(Validator::validateFloat($control)); Assert::same('', $control->value); diff --git a/tests/Forms/Forms.callbackParameters.phpt b/tests/Forms/Forms.callbackParameters.phpt index b311cdc19..aaddc22b2 100644 --- a/tests/Forms/Forms.callbackParameters.phpt +++ b/tests/Forms/Forms.callbackParameters.phpt @@ -15,7 +15,7 @@ $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['text'] = 'a'; $_POST['btn'] = 'b'; -$form = new Form(); +$form = new Form; $form->addText('text'); $form->addSubmit('btn'); From 1c0938a8a1d378ee962ea871ad6550b32376aea6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 17 Aug 2017 14:06:16 +0200 Subject: [PATCH 07/11] addError() by default translates messages (BC break) --- src/Forms/Controls/BaseControl.php | 4 ++-- src/Forms/Controls/HiddenField.php | 4 ++-- src/Forms/Form.php | 5 ++++- src/Forms/Rules.php | 2 +- tests/Forms/Controls.translate().phpt | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Forms/Controls/BaseControl.php b/src/Forms/Controls/BaseControl.php index 145db0a46..ace5d7eeb 100644 --- a/src/Forms/Controls/BaseControl.php +++ b/src/Forms/Controls/BaseControl.php @@ -504,9 +504,9 @@ public function validate() * @param string|object * @return void */ - public function addError($message) + public function addError($message, $translate = true) { - $this->errors[] = $message; + $this->errors[] = $translate ? $this->translate($message) : $message; } diff --git a/src/Forms/Controls/HiddenField.php b/src/Forms/Controls/HiddenField.php index fd023026d..f9c75dacf 100644 --- a/src/Forms/Controls/HiddenField.php +++ b/src/Forms/Controls/HiddenField.php @@ -81,8 +81,8 @@ public function getLabel($caption = null) * @param string|object * @return void */ - public function addError($message) + public function addError($message, $translate = true) { - $this->getForm()->addError($message); + $this->getForm()->addError($message, $translate); } } diff --git a/src/Forms/Form.php b/src/Forms/Form.php index c75aee89b..5aa53ea39 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -534,8 +534,11 @@ public function validateMaxPostSize() * @param string|object * @return void */ - public function addError($message) + public function addError($message, $translate = true) { + if ($translate && $this->translator) { + $message = $this->translator->translate($message); + } $this->errors[] = $message; } diff --git a/src/Forms/Rules.php b/src/Forms/Rules.php index e8cf2d6af..8a2d99133 100644 --- a/src/Forms/Rules.php +++ b/src/Forms/Rules.php @@ -246,7 +246,7 @@ public function validate($emptyOptional = false) return false; } elseif (!$success && !$rule->branch) { - $rule->control->addError(Validator::formatMessage($rule, true)); + $rule->control->addError(Validator::formatMessage($rule, true), false); return false; } } diff --git a/tests/Forms/Controls.translate().phpt b/tests/Forms/Controls.translate().phpt index 871095ef6..e5f609c4a 100644 --- a/tests/Forms/Controls.translate().phpt +++ b/tests/Forms/Controls.translate().phpt @@ -70,10 +70,10 @@ test(function () { $name = $form->addText('name', 'Your name'); $name->addError('Error message'); - $name->addError($w = new StringWrapper('Your name')); + $name->addError(new StringWrapper('Your name')); Assert::same([ 'Error message', - $w, + 'StringWrapper', ], $name->getErrors()); }); From 7b4b5252336c585063bb7c0d9218fd41f46b5254 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 17 Aug 2017 13:32:14 +0200 Subject: [PATCH 08/11] Revert "DefaultFormRenderer: added error message translation (#145)" [Closes #162] This reverts commit 7c4e4ca2c4533022635fa97b7d4637b7456f1618. --- src/Forms/Rendering/DefaultFormRenderer.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Forms/Rendering/DefaultFormRenderer.php b/src/Forms/Rendering/DefaultFormRenderer.php index e6f68aa99..3c0f19fca 100644 --- a/src/Forms/Rendering/DefaultFormRenderer.php +++ b/src/Forms/Rendering/DefaultFormRenderer.php @@ -214,10 +214,6 @@ public function renderEnd() */ public function renderErrors(Nette\Forms\IControl $control = null, $own = true) { - $translator = $control - ? ($control instanceof \Nette\Forms\Controls\BaseControl ? $control->getTranslator() : null) - : $this->form->getTranslator(); - $errors = $control ? $control->getErrors() : ($own ? $this->form->getOwnErrors() : $this->form->getErrors()); @@ -232,7 +228,7 @@ public function renderErrors(Nette\Forms\IControl $control = null, $own = true) if ($error instanceof IHtmlString) { $item->addHtml($error); } else { - $item->setText($translator ? $translator->translate($error) : $error); + $item->setText($error); } $container->addHtml($item); } From d56f78ce1b70c137c857e78a1cd5e122bb8e8b27 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 17 Aug 2017 14:27:28 +0200 Subject: [PATCH 09/11] added Form::reset() --- src/Forms/Form.php | 12 +++++ tests/Forms/Container.values.phpt | 83 +++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/src/Forms/Form.php b/src/Forms/Form.php index 5aa53ea39..a2044c0c0 100644 --- a/src/Forms/Form.php +++ b/src/Forms/Form.php @@ -465,6 +465,18 @@ private function invokeHandlers($handlers, $button = null) } + /** + * Resets form. + * @return static + */ + public function reset() + { + $this->setSubmittedBy(null); + $this->setValues([], true); + return $this; + } + + /** * Internal: returns submitted HTTP data or null when form was not submitted. * @return array|null diff --git a/tests/Forms/Container.values.phpt b/tests/Forms/Container.values.phpt index 89890d79d..fba16eaf7 100644 --- a/tests/Forms/Container.values.phpt +++ b/tests/Forms/Container.values.phpt @@ -74,3 +74,86 @@ Assert::equal(ArrayHash::from([ 'name' => '', ]), ]), $form->getValues()); + + +$form->setValues([ + 'name' => 'new1', + 'first' => [ + 'name' => 'new2', + ], +]); + +Assert::truthy($form->isSubmitted()); +Assert::equal(ArrayHash::from([ + 'name' => 'new1', + 'first' => ArrayHash::from([ + 'name' => 'new2', + 'age' => '40', + 'second' => ArrayHash::from([ + 'name' => 'david', + ]), + ]), + 'invalid' => ArrayHash::from([ + 'name' => '', + ]), +]), $form->getValues()); + + +$form->setValues([ + 'name' => 'new1', + 'first' => [ + 'name' => 'new2', + ], +], true); + +Assert::truthy($form->isSubmitted()); +Assert::equal(ArrayHash::from([ + 'name' => 'new1', + 'first' => ArrayHash::from([ + 'name' => 'new2', + 'age' => '', + 'second' => ArrayHash::from([ + 'name' => '', + ]), + ]), + 'invalid' => ArrayHash::from([ + 'name' => '', + ]), +]), $form->getValues()); + + +$form->reset(); + +Assert::false($form->isSubmitted()); +Assert::equal(ArrayHash::from([ + 'name' => '', + 'first' => ArrayHash::from([ + 'name' => '', + 'age' => '', + 'second' => ArrayHash::from([ + 'name' => '', + ]), + ]), + 'invalid' => ArrayHash::from([ + 'name' => '', + ]), +]), $form->getValues()); + + +$form->setDefaults([ + 'name' => 'new3', +]); + +Assert::equal(ArrayHash::from([ + 'name' => 'new3', + 'first' => ArrayHash::from([ + 'name' => '', + 'age' => '', + 'second' => ArrayHash::from([ + 'name' => '', + ]), + ]), + 'invalid' => ArrayHash::from([ + 'name' => '', + ]), +]), $form->getValues()); From 36d9fe7a3ba9bad9ee6b181a9cd38c6cbf774d3c Mon Sep 17 00:00:00 2001 From: Vlasta Vesely Date: Sun, 20 Aug 2017 16:54:51 +0200 Subject: [PATCH 10/11] tests: update (#164) --- tests/Forms/Forms.renderer.translate.phpt | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/Forms/Forms.renderer.translate.phpt b/tests/Forms/Forms.renderer.translate.phpt index 8afce201c..4d963273b 100644 --- a/tests/Forms/Forms.renderer.translate.phpt +++ b/tests/Forms/Forms.renderer.translate.phpt @@ -15,15 +15,20 @@ require __DIR__ . '/../bootstrap.php'; class Translator implements ITranslator { + public $counter = []; + + public function translate($message, $count = null) { + @$this->counter[$message]++; // @ intentionally return strtoupper($message); } } +$translator = new Translator; $form = new Form; -$form->setTranslator(new Translator); +$form->setTranslator($translator); $form->setAction('test'); $form->addError('Login failed'); @@ -38,3 +43,17 @@ $form->addSubmit('submit', 'Send'); Assert::matchFile(__DIR__ . '/Forms.renderer.translate.expect', $form->__toString(true)); + + +// Checking whether translation is not duplicated +Assert::same([ + 'Login failed' => 1, + 'Weak password' => 1, + 'Username' => 1, + 'or email' => 1, + 'Please enter your username' => 1, + 'Password' => 1, + 'This field is required.' => 1, + 'Minimal length is %d chars' => 1, + 'Send' => 1, +], $translator->counter); From 70224011c6ca3941f5aeeb4efbe31d2cb3b13652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mor=C3=A1vek?= Date: Sat, 22 Jul 2017 22:01:27 +0200 Subject: [PATCH 11/11] FormMacros: fix edcompatibility between n:class macro and n:name form macro. (#159) --- src/Bridges/FormsLatte/FormMacros.php | 11 ++++++--- tests/Forms.Latte/FormMacros.forms.phpt | 2 ++ .../expected/FormMacros.forms.html | 24 ++++++++++++------- .../expected/FormMacros.forms.phtml | 20 +++++++++++++++- tests/Forms.Latte/templates/forms.latte | 5 ++++ 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/Bridges/FormsLatte/FormMacros.php b/src/Bridges/FormsLatte/FormMacros.php index 789b7bc61..20186dd59 100644 --- a/src/Bridges/FormsLatte/FormMacros.php +++ b/src/Bridges/FormsLatte/FormMacros.php @@ -163,6 +163,11 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer) $tagName = strtolower($node->htmlNode->name); $node->empty = $tagName === 'input'; + $definedHtmlAttributes = array_keys($node->htmlNode->attrs); + if (isset($node->htmlNode->macroAttrs['class'])) { + $definedHtmlAttributes[] = 'class'; + } + if ($tagName === 'form') { $node->openingCode = $writer->write( 'global->formsStack[] = ' @@ -172,17 +177,17 @@ public function macroNameAttr(MacroNode $node, PhpWriter $writer) ); return $writer->write( 'echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), %0.var, false)', - array_fill_keys(array_keys($node->htmlNode->attrs), null) + array_fill_keys($definedHtmlAttributes, null) ); } else { $method = $tagName === 'label' ? 'getLabel' : 'getControl'; return $writer->write( '$_input = ' . ($name[0] === '$' ? 'is_object(%0.word) ? %0.word : ' : '') . 'end($this->global->formsStack)[%0.word]; echo $_input->%1.raw' - . ($node->htmlNode->attrs ? '->addAttributes(%2.var)' : '') . '->attributes()', + . ($definedHtmlAttributes ? '->addAttributes(%2.var)' : '') . '->attributes()', $name, $method . 'Part(' . implode(', ', array_map([$writer, 'formatWord'], $words)) . ')', - array_fill_keys(array_keys($node->htmlNode->attrs), null) + array_fill_keys($definedHtmlAttributes, null) ); } } diff --git a/tests/Forms.Latte/FormMacros.forms.phpt b/tests/Forms.Latte/FormMacros.forms.phpt index a7184d4df..c696ffde2 100644 --- a/tests/Forms.Latte/FormMacros.forms.phpt +++ b/tests/Forms.Latte/FormMacros.forms.phpt @@ -28,8 +28,10 @@ class MyControl extends Nette\Forms\Controls\BaseControl $form = new Form; +$form->getElementPrototype()->addClass('form-class'); $form->addHidden('id'); $form->addText('username', 'Username:'); // must have just one textfield to generate IE fix +$form['username']->getControlPrototype()->addClass('control-class'); $form->addRadioList('sex', 'Sex:', ['m' => 'male', 'f' => 'female']); $form->addSelect('select', null, ['m' => 'male', 'f' => 'female']); $form->addTextArea('area', null)->setValue('one +
@@ -9,13 +9,13 @@ - + error error
- + error @@ -52,7 +52,7 @@ - + @@ -60,11 +60,11 @@ - +
-
+ @@ -91,13 +91,19 @@ - +
-
- + + + +
+ + +
+
diff --git a/tests/Forms.Latte/expected/FormMacros.forms.phtml b/tests/Forms.Latte/expected/FormMacros.forms.phtml index 7f59824b9..46737a98a 100644 --- a/tests/Forms.Latte/expected/FormMacros.forms.phtml +++ b/tests/Forms.Latte/expected/FormMacros.forms.phtml @@ -202,6 +202,24 @@ ?> +global->formsStack[] = $this->global->uiControl["myForm"]; + ?>global->formsStack), array ( + 'class' => NULL, + ), false) ?>> + global->formsStack)["username"]; + echo $_input->getControlPart()->addAttributes(array ( + 'class' => NULL, + ))->attributes(); + if ($_tmp = array_filter(['nclass'])) echo ' class="', LR\Filters::escapeHtmlAttr(implode(" ", array_unique($_tmp))), '"' ?>> +global->formsStack), false); +?> + + global->formsStack[] = is_object($this->global->uiControl['myForm']) ? $this->global->uiControl['myForm'] : $this->global->uiControl[$this->global->uiControl['myForm']]; ?>getControlPart()->attributes() ?>>getControl()->getHtml() ?> -