Skip to content

Commit ed03b4b

Browse files
committed
Revert "TextBase: emptyValue is removed from value in validate()" - getValue() can be called before validation
This reverts commit f6ba8bc.
1 parent 7c4e4ca commit ed03b4b

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

src/Forms/Controls/TextBase.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function setValue($value)
5353
*/
5454
public function getValue()
5555
{
56-
return $this->nullable && $this->value === '' ? NULL : $this->value;
56+
$value = $this->value === Strings::trim($this->translate($this->emptyValue)) ? '' : $this->value;
57+
return $this->nullable && $value === '' ? NULL : $value;
5758
}
5859

5960

@@ -145,16 +146,4 @@ public function addRule($validator, $errorMessage = NULL, $arg = NULL)
145146
return parent::addRule($validator, $errorMessage, $arg);
146147
}
147148

148-
149-
/**
150-
* Performs the server side validation.
151-
*/
152-
public function validate(): void
153-
{
154-
if ($this->value === Strings::trim($this->translate($this->emptyValue))) {
155-
$this->value = '';
156-
}
157-
parent::validate();
158-
}
159-
160149
}

tests/Forms/Controls.TextBase.loadData.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ test(function () { // empty value
4747
$input = $form->addText('url')
4848
->setEmptyValue('nette.org');
4949

50-
$input->validate();
5150
Assert::same('', $input->getValue());
5251
});
5352

@@ -59,7 +58,6 @@ test(function () { // empty value
5958
$input = $form->addText('phone')
6059
->setEmptyValue('+420 ');
6160

62-
$input->validate();
6361
Assert::same('', $input->getValue());
6462
});
6563

0 commit comments

Comments
 (0)