Skip to content

Commit 22b80ec

Browse files
chemixdg
authored andcommitted
TextBase: fixed setEmptyValue() and space at the end of the string [Closes #35]
1 parent 9af766b commit 22b80ec

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Forms/Controls/TextBase.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
namespace Nette\Forms\Controls;
99

1010
use Nette,
11-
Nette\Forms\Form;
11+
Nette\Forms\Form,
12+
Nette\Utils\Strings;
1213

1314

1415
/**
@@ -55,12 +56,12 @@ public function getValue()
5556
{
5657
$value = $this->value;
5758
if (!empty($this->control->maxlength)) {
58-
$value = Nette\Utils\Strings::substring($value, 0, $this->control->maxlength);
59+
$value = Strings::substring($value, 0, $this->control->maxlength);
5960
}
6061
foreach ($this->filters as $filter) {
6162
$value = (string) call_user_func($filter, $value);
6263
}
63-
return $value === $this->translate($this->emptyValue) ? '' : $value;
64+
return $value === Strings::trim($this->translate($this->emptyValue)) ? '' : $value;
6465
}
6566

6667

tests/Forms/Controls.TextBase.loadData.phpt

+11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ test(function() { // empty value
4949
});
5050

5151

52+
test(function() { // empty value
53+
$_POST = array('phone' => '+420 ');
54+
55+
$form = new Form;
56+
$input = $form->addText('phone')
57+
->setEmptyValue('+420 ');
58+
59+
Assert::same( '', $input->getValue() );
60+
});
61+
62+
5263
test(function() { // invalid UTF
5364
$_POST = array('invalidutf' => "invalid\xAA\xAA\xAAutf");
5465

0 commit comments

Comments
 (0)