Skip to content

Commit d898010

Browse files
committed
TextBase: emptyValue is removed from value in validate()
1 parent e58f331 commit d898010

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Forms/Controls/TextBase.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function setValue($value)
4848
*/
4949
public function getValue()
5050
{
51-
return $this->value === Strings::trim($this->translate($this->emptyValue)) ? '' : $this->value;
51+
return $this->value;
5252
}
5353

5454

@@ -133,4 +133,17 @@ public function addRule($validator, $message = NULL, $arg = NULL)
133133
return parent::addRule($validator, $message, $arg);
134134
}
135135

136+
137+
/**
138+
* Performs the server side validation.
139+
* @return void
140+
*/
141+
public function validate()
142+
{
143+
if ($this->value === Strings::trim($this->translate($this->emptyValue))) {
144+
$this->value = '';
145+
}
146+
parent::validate();
147+
}
148+
136149
}

tests/Forms/Controls.TextBase.loadData.phpt

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

48+
$input->validate();
4849
Assert::same('', $input->getValue());
4950
});
5051

@@ -56,6 +57,7 @@ test(function () { // empty value
5657
$input = $form->addText('phone')
5758
->setEmptyValue('+420 ');
5859

60+
$input->validate();
5961
Assert::same('', $input->getValue());
6062
});
6163

0 commit comments

Comments
 (0)